diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index 8e3dde7f0..cd4b6ae96 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -247,7 +247,7 @@ static UICompositeViewDescription *compositeDescription = nil; [NSString stringWithFormat:NSLocalizedString(@"Do you want to leave this conversation?", nil)]; [UIConfirmationDialog ShowWithMessage:msg cancelMessage:nil - confirmMessage:nil + confirmMessage:NSLocalizedString(@"LEAVE", nil) onCancelClick:^() {} onConfirmationClick:^() { linphone_chat_room_leave(_room); diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 35db8d26e..9e240acc4 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -479,7 +479,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onDeleteClick:(id)sender { LOGI(@"onDeleteClick"); - NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete selected messages?", nil)]; + NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete and selected messages?", nil)]; [UIConfirmationDialog ShowWithMessage:msg cancelMessage:nil confirmMessage:nil diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 31f04cc53..1ee7949b9 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -226,7 +226,7 @@ void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomStat forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { NSString *msg = - [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete this conversation?", nil)]; + [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete and leave this conversation?", nil)]; [UIConfirmationDialog ShowWithMessage:msg cancelMessage:nil confirmMessage:nil diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index ca6ce435a..bf8e61c83 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -95,7 +95,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onDeleteClick:(id)sender { NSString *msg = - [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete selected conversations?", nil)]; + [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete and leave the selected conversations?", nil)]; [UIConfirmationDialog ShowWithMessage:msg cancelMessage:nil confirmMessage:nil diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index cb293eae3..93c7b1e1b 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -31,13 +31,14 @@ BOOL startedInBackground; } -- (void)registerForNotifications:(UIApplication *)app; +- (void)registerForNotifications; @property (nonatomic, retain) UIAlertController *waitingIndicator; @property (nonatomic, retain) NSString *configURL; @property (nonatomic, strong) UIWindow* window; @property PKPushRegistry* voipRegistry; @property ProviderDelegate *del; +@property BOOL alreadyRegisteredForNotification; @end diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index a456eea38..fc9fc78ab 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -43,6 +43,7 @@ if (self != nil) { startedInBackground = FALSE; } + _alreadyRegisteredForNotification = false; return self; [[UIApplication sharedApplication] setDelegate:self]; } @@ -58,25 +59,22 @@ LOGI(@"%@", NSStringFromSelector(_cmd)); LinphoneCall *call = linphone_core_get_current_call(LC); - if (call) { - /* save call context */ - LinphoneManager *instance = LinphoneManager.instance; - instance->currentCallContextBeforeGoingBackground.call = call; - instance->currentCallContextBeforeGoingBackground.cameraIsEnabled = linphone_call_camera_enabled(call); + if (!call) + return; - const LinphoneCallParams *params = linphone_call_get_current_params(call); - if (linphone_call_params_video_enabled(params)) { - linphone_call_enable_camera(call, false); - } - } + /* save call context */ + LinphoneManager *instance = LinphoneManager.instance; + instance->currentCallContextBeforeGoingBackground.call = call; + instance->currentCallContextBeforeGoingBackground.cameraIsEnabled = linphone_call_camera_enabled(call); - if (![LinphoneManager.instance resignActive]) { - } + const LinphoneCallParams *params = linphone_call_get_current_params(call); + if (linphone_call_params_video_enabled(params)) + linphone_call_enable_camera(call, false); } - (void)applicationDidBecomeActive:(UIApplication *)application { LOGI(@"%@", NSStringFromSelector(_cmd)); - [self registerForNotifications:[UIApplication sharedApplication]]; + [self registerForNotifications]; if (startedInBackground) { startedInBackground = FALSE; [PhoneMainView.instance startUp]; @@ -219,85 +217,89 @@ } -- (void)registerForNotifications:(UIApplication *)app { +- (void)registerForNotifications { + if (_alreadyRegisteredForNotification) + return; + + _alreadyRegisteredForNotification = true; self.voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()]; self.voipRegistry.delegate = self; // Initiate registration. self.voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; - if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) { - // Call category - UNNotificationAction *act_ans = - [UNNotificationAction actionWithIdentifier:@"Answer" - title:NSLocalizedString(@"Answer", nil) - options:UNNotificationActionOptionForeground]; - UNNotificationAction *act_dec = [UNNotificationAction actionWithIdentifier:@"Decline" - title:NSLocalizedString(@"Decline", nil) + if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_9_x_Max) + return; + + LOGI(@"Registering for UNNotifications"); + // Call category + UNNotificationAction *act_ans = + [UNNotificationAction actionWithIdentifier:@"Answer" + title:NSLocalizedString(@"Answer", nil) + options:UNNotificationActionOptionForeground]; + UNNotificationAction *act_dec = [UNNotificationAction actionWithIdentifier:@"Decline" + title:NSLocalizedString(@"Decline", nil) + options:UNNotificationActionOptionNone]; + UNNotificationCategory *cat_call = + [UNNotificationCategory categoryWithIdentifier:@"call_cat" + actions:[NSArray arrayWithObjects:act_ans, act_dec, nil] + intentIdentifiers:[[NSMutableArray alloc] init] + options:UNNotificationCategoryOptionCustomDismissAction]; + // Msg category + UNTextInputNotificationAction *act_reply = + [UNTextInputNotificationAction actionWithIdentifier:@"Reply" + title:NSLocalizedString(@"Reply", nil) + options:UNNotificationActionOptionNone]; + UNNotificationAction *act_seen = + [UNNotificationAction actionWithIdentifier:@"Seen" + title:NSLocalizedString(@"Mark as seen", nil) + options:UNNotificationActionOptionNone]; + UNNotificationCategory *cat_msg = + [UNNotificationCategory categoryWithIdentifier:@"msg_cat" + actions:[NSArray arrayWithObjects:act_reply, act_seen, nil] + intentIdentifiers:[[NSMutableArray alloc] init] + options:UNNotificationCategoryOptionCustomDismissAction]; + + // Video Request Category + UNNotificationAction *act_accept = + [UNNotificationAction actionWithIdentifier:@"Accept" + title:NSLocalizedString(@"Accept", nil) + options:UNNotificationActionOptionForeground]; + + UNNotificationAction *act_refuse = [UNNotificationAction actionWithIdentifier:@"Cancel" + title:NSLocalizedString(@"Cancel", nil) + options:UNNotificationActionOptionNone]; + UNNotificationCategory *video_call = + [UNNotificationCategory categoryWithIdentifier:@"video_request" + actions:[NSArray arrayWithObjects:act_accept, act_refuse, nil] + intentIdentifiers:[[NSMutableArray alloc] init] + options:UNNotificationCategoryOptionCustomDismissAction]; + + // ZRTP verification category + UNNotificationAction *act_confirm = [UNNotificationAction actionWithIdentifier:@"Confirm" + title:NSLocalizedString(@"Accept", nil) options:UNNotificationActionOptionNone]; - UNNotificationCategory *cat_call = - [UNNotificationCategory categoryWithIdentifier:@"call_cat" - actions:[NSArray arrayWithObjects:act_ans, act_dec, nil] - intentIdentifiers:[[NSMutableArray alloc] init] - options:UNNotificationCategoryOptionCustomDismissAction]; - // Msg category - UNTextInputNotificationAction *act_reply = - [UNTextInputNotificationAction actionWithIdentifier:@"Reply" - title:NSLocalizedString(@"Reply", nil) - options:UNNotificationActionOptionNone]; - UNNotificationAction *act_seen = - [UNNotificationAction actionWithIdentifier:@"Seen" - title:NSLocalizedString(@"Mark as seen", nil) - options:UNNotificationActionOptionNone]; - UNNotificationCategory *cat_msg = - [UNNotificationCategory categoryWithIdentifier:@"msg_cat" - actions:[NSArray arrayWithObjects:act_reply, act_seen, nil] - intentIdentifiers:[[NSMutableArray alloc] init] - options:UNNotificationCategoryOptionCustomDismissAction]; - // Video Request Category - UNNotificationAction *act_accept = - [UNNotificationAction actionWithIdentifier:@"Accept" - title:NSLocalizedString(@"Accept", nil) - options:UNNotificationActionOptionForeground]; + UNNotificationAction *act_deny = [UNNotificationAction actionWithIdentifier:@"Deny" + title:NSLocalizedString(@"Deny", nil) + options:UNNotificationActionOptionNone]; + UNNotificationCategory *cat_zrtp = + [UNNotificationCategory categoryWithIdentifier:@"zrtp_request" + actions:[NSArray arrayWithObjects:act_confirm, act_deny, nil] + intentIdentifiers:[[NSMutableArray alloc] init] + options:UNNotificationCategoryOptionCustomDismissAction]; - UNNotificationAction *act_refuse = [UNNotificationAction actionWithIdentifier:@"Cancel" - title:NSLocalizedString(@"Cancel", nil) - options:UNNotificationActionOptionNone]; - UNNotificationCategory *video_call = - [UNNotificationCategory categoryWithIdentifier:@"video_request" - actions:[NSArray arrayWithObjects:act_accept, act_refuse, nil] - intentIdentifiers:[[NSMutableArray alloc] init] - options:UNNotificationCategoryOptionCustomDismissAction]; - - // ZRTP verification category - UNNotificationAction *act_confirm = [UNNotificationAction actionWithIdentifier:@"Confirm" - title:NSLocalizedString(@"Accept", nil) - options:UNNotificationActionOptionNone]; - - UNNotificationAction *act_deny = [UNNotificationAction actionWithIdentifier:@"Deny" - title:NSLocalizedString(@"Deny", nil) - options:UNNotificationActionOptionNone]; - UNNotificationCategory *cat_zrtp = - [UNNotificationCategory categoryWithIdentifier:@"zrtp_request" - actions:[NSArray arrayWithObjects:act_confirm, act_deny, nil] - intentIdentifiers:[[NSMutableArray alloc] init] - options:UNNotificationCategoryOptionCustomDismissAction]; - - [UNUserNotificationCenter currentNotificationCenter].delegate = self; - [[UNUserNotificationCenter currentNotificationCenter] - requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | - UNAuthorizationOptionBadge) - completionHandler:^(BOOL granted, NSError *_Nullable error) { - // Enable or disable features based on authorization. - if (error) { - LOGD(error.description); - } - }]; - NSSet *categories = [NSSet setWithObjects:cat_call, cat_msg, video_call, cat_zrtp, nil]; - [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories]; - } + [UNUserNotificationCenter currentNotificationCenter].delegate = self; + [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) + completionHandler:^(BOOL granted, NSError *_Nullable error) { + // Enable or disable features based on authorization. + if (error) + LOGD(error.description); + }]; + NSSet *categories = [NSSet setWithObjects:cat_call, cat_msg, video_call, cat_zrtp, nil]; + [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories]; } + #pragma deploymate pop - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { @@ -444,6 +446,8 @@ if ([self addLongTaskIDforCallID:callId] && [UIApplication sharedApplication].applicationState != UIApplicationStateActive) [LinphoneManager.instance startPushLongRunningTask:loc_key callId:callId]; + [self registerForNotifications]; + // if we receive a push notification, it is probably because our TCP background socket was no more working. // As a result, break it and refresh registers in order to make sure to receive incoming INVITE or MESSAGE if (!linphone_core_is_network_reachable(LC)) { diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 8f9e21656..6473aabe0 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -32,6 +32,7 @@ #import #import "LinphoneCoreSettingsStore.h" +#import "LinphoneAppDelegate.h" #import "LinphoneManager.h" #import "Utils/AudioHelper.h" #import "Utils/FileTransferDelegate.h" @@ -1070,6 +1071,9 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAut #pragma mark - Text Received Functions - (void)onMessageReceived:(LinphoneCore *)lc room:(LinphoneChatRoom *)room message:(LinphoneChatMessage *)msg { + UIApplication *app = [UIApplication sharedApplication]; + LinphoneAppDelegate *delegate = (LinphoneAppDelegate *)app.delegate; + [delegate registerForNotifications]; #pragma deploymate push "ignored-api-availability" if (_silentPushCompletion) { // we were woken up by a silent push. Call the completion handler with NEWDATA diff --git a/Classes/SettingsView.m b/Classes/SettingsView.m index d23d7d61b..3ab0bbe03 100644 --- a/Classes/SettingsView.m +++ b/Classes/SettingsView.m @@ -510,7 +510,7 @@ void update_hash_cbs(LinphoneAccountCreator *creator, LinphoneAccountCreatorStat // we have to register again to the iOS notification, because we change the actions associated with IM_MSG UIApplication *app = [UIApplication sharedApplication]; LinphoneAppDelegate *delegate = (LinphoneAppDelegate *)app.delegate; - [delegate registerForNotifications:app]; + [delegate registerForNotifications]; } for (NSString *key in keys) {