Commit 8ee86eea authored by DanmeiChen's avatar DanmeiChen
Browse files

fix reload device on route change callback

parent 6dab0c6d
......@@ -35,23 +35,16 @@
IosAppDelegate is an object taking care of all application delegate's notifications and iteartion:
UIApplicationDidEnterBackgroundNotification
UIApplicationWillEnterForegroundNotification
AVAudioSessionRouteChangeNotification
iteration
Its lifecicle is the same as the one from linphonecore init to destroy.
*/
@interface IosAppDelegate : IosObject
- (id)initWithCore:(std::shared_ptr<LinphonePrivate::Core>)core;
@end
/*
IosHandler is an object taking cahrge of all ios system's notifications:
AVAudioSessionRouteChangeNotification
Its lifecicle is the same as the one from core start to stop.
*/
@interface IosHandler : IosObject
@interface IosAppDelegate : IosObject {
BOOL mStopAsyncEnd;
}
- (id)initWithCore:(std::shared_ptr<LinphonePrivate::Core>)core;
- (void)reloadDeviceOnRouteChangeCallback: (NSNotification *) notif;
- (void)onStopAsyncEnd: (BOOL)stop;
@end
......@@ -52,14 +52,19 @@
selector:@selector(didEnterForeground:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(reloadDeviceOnRouteChangeCallback:)
name:AVAudioSessionRouteChangeNotification
object:nil];
mStopAsyncEnd = false;
}
return self;
}
- (void)dealloc {
[super dealloc];
[NSNotificationCenter.defaultCenter removeObserver:self];
[super dealloc];
}
- (void)didEnterBackground:(NSNotification *)notif {
......@@ -79,29 +84,12 @@
linphone_core_iterate([self getCore]->getCCore());
}
@end
@implementation IosHandler
- (id)initWithCore:(std::shared_ptr<LinphonePrivate::Core>)core {
self = [super initWithCore:core];
if (self != nil) {
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(reloadDeviceOnRouteChangeCallback:)
name:AVAudioSessionRouteChangeNotification
object:nil];
}
return self;
}
- (void)dealloc {
[super dealloc];
[NSNotificationCenter.defaultCenter removeObserver:self];
}
- (void)reloadDeviceOnRouteChangeCallback: (NSNotification *) notif
{
if (mStopAsyncEnd) {
ms_warning("[reloadDeviceOnRouteChangeCallback] linphone_stop_async_end is already called, skipping");
return;
}
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
NSDictionary * userInfo = [notif userInfo];
......@@ -227,6 +215,10 @@
});
}
- (void)onStopAsyncEnd: (BOOL)stop {
mStopAsyncEnd = stop;
}
@end
......
......@@ -115,7 +115,6 @@ private:
SCNetworkReachabilityFlags mCurrentFlags = 0;
bool mNetworkMonitoringEnabled = false;
static const string Framework;
IosHandler *mHandler = NULL;
IosAppDelegate *mAppDelegate = NULL; /* auto didEnterBackground/didEnterForeground and other callbacks */
bool mStart = false; /* generic platformhelper's funcs only work when mStart is true */
bool mUseAppDelgate = false; /* app delegate is only used by main core*/
......@@ -141,7 +140,6 @@ void IosPlatformHelpers::start (std::shared_ptr<LinphonePrivate::Core> core) {
mCpuLockTaskId = 0;
mNetworkReachable = 0; // wait until monitor to give a status;
mSharedCoreHelpers = createIosSharedCoreHelpers(core);
mHandler = [[IosHandler alloc] initWithCore:core];
string cpimPath = getResourceDirPath(Framework, "cpim_grammar");
if (!cpimPath.empty())
......@@ -165,6 +163,7 @@ void IosPlatformHelpers::start (std::shared_ptr<LinphonePrivate::Core> core) {
ms_message("IosPlatformHelpers is fully started");
mStart = true;
[mAppDelegate onStopAsyncEnd:false];
}
void IosPlatformHelpers::stop () {
......@@ -321,7 +320,7 @@ void IosPlatformHelpers::onLinphoneCoreStop() {
}
// To avoid trigger callbacks of mHandler after linphone core stop
[mHandler dealloc];
[mAppDelegate onStopAsyncEnd:true];
getSharedCoreHelpers()->onLinphoneCoreStop();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment