diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index ec89ddc2d..4e731bc61 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -25,7 +25,6 @@ #import "CoreTelephony/CTCall.h" #import "ConsoleViewController.h" -#import "MoreViewController.h" #import "LinphoneCoreSettingsStore.h" #include "LinphoneManager.h" @@ -118,7 +117,8 @@ int __aeabi_idiv(int a, int b) { - (void)applicationDidBecomeActive:(UIApplication *)application { if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground - && ![[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"]) { + && (![[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"] || + ![[NSUserDefaults standardUserDefaults] boolForKey:@"backgroundmode_preference"])) { // autoboot disabled, doing nothing return; } @@ -199,7 +199,8 @@ int __aeabi_idiv(int a, int b) { if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)] && [UIApplication sharedApplication].applicationState == UIApplicationStateBackground - && ![[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"]) { + && (![[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"] || + ![[NSUserDefaults standardUserDefaults] boolForKey:@"backgroundmode_preference"])) { // autoboot disabled, doing nothing } else { [self startApplication]; @@ -228,6 +229,10 @@ int __aeabi_idiv(int a, int b) { - (void)applicationWillTerminate:(UIApplication *)application { } +- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { + //NSLog(@"%@", userInfo); +} + - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { if([notification.userInfo objectForKey:@"call"] != nil) { LinphoneCall* call; @@ -247,4 +252,18 @@ int __aeabi_idiv(int a, int b) { } } + +#pragma mark - PushNotification Functions + +- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { + [LinphoneLogger log:LinphoneLoggerDebug format:@"PushNotification: Token %@", deviceToken]; + //NSLog(@"%@", deviceToken); + [[LinphoneManager instance] setPushNotificationToken:deviceToken]; +} + +- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { + [LinphoneLogger log:LinphoneLoggerDebug format:@"PushNotification: Error %@", error]; + [[LinphoneManager instance] setPushNotificationToken:nil]; +} + @end diff --git a/Classes/LinphoneCoreSettingsStore.h b/Classes/LinphoneCoreSettingsStore.h index fd6c162f7..ab6b214c8 100644 --- a/Classes/LinphoneCoreSettingsStore.h +++ b/Classes/LinphoneCoreSettingsStore.h @@ -27,6 +27,7 @@ NSDictionary *changedDict; } --(void) transformLinphoneCoreToKeys; +- (void)synchronizeAccount; +- (void)transformLinphoneCoreToKeys; @end diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 23e303f35..2bc8bece6 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -182,12 +182,16 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); [self setBool: lp_config_get_int(linphone_core_get_config(lc),"app","debugenable_preference", 0) forKey:@"debugenable_preference"]; [self setBool: lp_config_get_int(linphone_core_get_config(lc),"app","check_config_disable_preference", 0) forKey:@"check_config_disable_preference"]; [self setBool: lp_config_get_int(linphone_core_get_config(lc),"app","wifi_only_preference", 0) forKey:@"wifi_only_preference"]; - [self setBool: lp_config_get_int(linphone_core_get_config(lc),"app","backgroundmode_preference", TRUE) forKey:@"backgroundmode_preference"]; + /*keep this one also in the standardUserDefaults so that it can be read before starting liblinphone*/ BOOL start_at_boot = TRUE; if ([[NSUserDefaults standardUserDefaults] objectForKey:@"start_at_boot_preference"]!=Nil) - start_at_boot=[[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"]; + start_at_boot = [[NSUserDefaults standardUserDefaults] boolForKey:@"start_at_boot_preference"]; [self setBool: start_at_boot forKey:@"start_at_boot_preference"]; + BOOL background_mode = TRUE; + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"backgroundmode_preference"]!=Nil) + background_mode =[[NSUserDefaults standardUserDefaults] boolForKey:@"backgroundmode_preference"]; + [self setBool: background_mode forKey:@"backgroundmode_preference"]; if (linphone_core_tunnel_available()){ /*FIXME: enhance linphonecore API to handle tunnel more easily in applications */ @@ -349,7 +353,19 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); linphone_proxy_config_set_dial_prefix(proxyCfg, [prefix cStringUsingEncoding:[NSString defaultCStringEncoding]]); } linphone_proxy_config_set_dial_escape_plus(proxyCfg,substitute_plus_by_00); - + + //Add custom parameter + NSData *tokenData = [[LinphoneManager instance] pushNotificationToken]; + if(tokenData != nil) { + const unsigned char *tokenBuffer = [tokenData bytes]; + NSMutableString *tokenString = [NSMutableString stringWithCapacity:[tokenData length]*2]; + for(int i = 0; i < [tokenData length]; ++i) { + [tokenString appendFormat:@"%02X", (unsigned int)tokenBuffer[i]]; + } + linphone_proxy_config_set_contact_parameters(proxyCfg, [[NSString stringWithFormat:@"APN=%@", tokenString] UTF8String]); + } + + linphone_core_add_proxy_config(lc,proxyCfg); //set to default proxy linphone_core_set_default_proxy(lc,proxyCfg); @@ -463,7 +479,9 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); /*keep this one also in the standardUserDefaults so that it can be read before starting liblinphone*/ BOOL start_at_boot = [self boolForKey:@"start_at_boot_preference"]; [[NSUserDefaults standardUserDefaults] setBool: start_at_boot forKey:@"start_at_boot_preference"]; - + BOOL background_mode = [self boolForKey:@"backgroundmode_preference"]; + [[NSUserDefaults standardUserDefaults] setBool: background_mode forKey:@"backgroundmode_preference"]; + // Force synchronize [[NSUserDefaults standardUserDefaults] synchronize]; diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 34a82c210..b2b3dcabd 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -106,6 +106,7 @@ typedef struct _LinphoneCallAppData { @property (readonly) const char* frontCamId; @property (readonly) const char* backCamId; @property (readonly) sqlite3* database; +@property (nonatomic, retain) NSData *pushNotificationToken; @end diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index d1b400faa..d2a7408f0 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -67,6 +67,7 @@ extern void libmsbcg729_init(); @synthesize settingsStore; @synthesize database; @synthesize fastAddressBook; +@synthesize pushNotificationToken; struct codec_name_pref_table{ const char *name; @@ -706,15 +707,10 @@ static LinphoneCoreVTable linphonec_vtable = { } - (void)becomeActive { - if (theLinphoneCore == nil) { - //back from standby and background mode is disabled - [self startLibLinphone]; - } else { - [self refreshRegisters]; - } + [self refreshRegisters]; + /*IOS specific*/ linphone_core_start_dtmf_stream(theLinphoneCore); - } - (void)beginInterruption { @@ -767,16 +763,17 @@ static LinphoneCoreVTable linphonec_vtable = { } - (BOOL)isSpeakerEnabled { + bool enabled = false; CFStringRef lNewRoute = CFSTR("Unknown"); UInt32 lNewRouteSize = sizeof(lNewRoute); OSStatus lStatus = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &lNewRouteSize, &lNewRoute); if (!lStatus && lNewRouteSize > 0) { NSString *route = (NSString *) lNewRoute; [LinphoneLogger logc:LinphoneLoggerLog format:"Current audio route is [%s]", [route cStringUsingEncoding:[NSString defaultCStringEncoding]]]; - return [route isEqualToString: @"Speaker"] || [route isEqualToString: @"SpeakerAndMicrophone"]; - } else { - return false; + enabled = [route isEqualToString: @"Speaker"] || [route isEqualToString: @"SpeakerAndMicrophone"]; + CFRelease(lNewRoute); } + return enabled; } @@ -852,4 +849,24 @@ static LinphoneCoreVTable linphonec_vtable = { linphone_call_params_destroy(lcallParams); } + +#pragma mark - Property Functions + +- (void)setPushNotificationToken:(NSData *)apushNotificationToken { + if(apushNotificationToken == pushNotificationToken) { + return; + } + if(pushNotificationToken != nil) { + [pushNotificationToken release]; + pushNotificationToken = nil; + } + + if(apushNotificationToken != nil) { + pushNotificationToken = [apushNotificationToken retain]; + } + if([LinphoneManager isLcReady]) { + [(LinphoneCoreSettingsStore*)settingsStore synchronizeAccount]; + } +} + @end diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index 91ea51d15..29b9f2460 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -421,7 +421,7 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys removeObject:@"video_menu"]; } [settingsController setHiddenKeys:hiddenKeys animated:TRUE]; - }else if([@"random_port_preference" compare: notif.object] == NSOrderedSame) { + } else if ([@"random_port_preference" compare: notif.object] == NSOrderedSame) { BOOL enable = [[notif.userInfo objectForKey:@"random_port_preference"] boolValue]; NSMutableSet *hiddenKeys = [NSMutableSet setWithSet:[settingsController hiddenKeys]]; if(enable) { @@ -430,6 +430,15 @@ static UICompositeViewDescription *compositeDescription = nil; [hiddenKeys removeObject:@"port_preference"]; } [settingsController setHiddenKeys:hiddenKeys animated:TRUE]; + } else if ([@"backgroundmode_preference" compare: notif.object] == NSOrderedSame) { + BOOL enable = [[notif.userInfo objectForKey:@"backgroundmode_preference"] boolValue]; + NSMutableSet *hiddenKeys = [NSMutableSet setWithSet:[settingsController hiddenKeys]]; + if(!enable) { + [hiddenKeys addObject:@"start_at_boot_preference"]; + } else { + [hiddenKeys removeObject:@"start_at_boot_preference"]; + } + [settingsController setHiddenKeys:hiddenKeys animated:TRUE]; } } @@ -454,6 +463,11 @@ static UICompositeViewDescription *compositeDescription = nil; UIDevice* device = [UIDevice currentDevice]; if (![device respondsToSelector:@selector(isMultitaskingSupported)] || ![device isMultitaskingSupported]) { [hiddenKeys addObject:@"backgroundmode_preference"]; + [hiddenKeys addObject:@"start_at_boot_preference"]; + } else { + if(![[[[LinphoneManager instance] settingsStore] objectForKey:@"backgroundmode_preference"] boolValue]) { + [hiddenKeys addObject:@"start_at_boot_preference"]; + } } [hiddenKeys addObject:@"enable_first_login_view_preference"]; diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index c25c0e9d7..771fa1c8e 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -68,7 +68,7 @@ + (NSString*)normalizeSipURI:(NSString*)address { NSString* ret = address; - if(![address hasPrefix:@"sip:"]) { + if([address rangeOfString:@"@"].location != NSNotFound && ![address hasPrefix:@"sip:"]) { ret = [@"sip:" stringByAppendingString:ret]; } return ret; diff --git a/Settings/InAppSettings.bundle/Advanced.plist b/Settings/InAppSettings.bundle/Advanced.plist index 13eecede9..4218c07f4 100644 --- a/Settings/InAppSettings.bundle/Advanced.plist +++ b/Settings/InAppSettings.bundle/Advanced.plist @@ -40,9 +40,9 @@ DefaultValue Key - start_at_boot_preference + backgroundmode_preference Title - Start at boot + Background mode Type PSToggleSwitchSpecifier @@ -50,9 +50,9 @@ DefaultValue Key - backgroundmode_preference + start_at_boot_preference Title - Background mode + Start at boot Type PSToggleSwitchSpecifier diff --git a/untitled.plist b/untitled.plist deleted file mode 100644 index ce373e19b..000000000 --- a/untitled.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - get-task-allow - - -