always display UNNotifications actions

This commit is contained in:
Benjamin Reis 2018-02-16 10:05:20 +01:00
parent 2f6ab88314
commit 9226f366ab
8 changed files with 97 additions and 88 deletions

View file

@ -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);

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)) {

View file

@ -32,6 +32,7 @@
#import <SystemConfiguration/SystemConfiguration.h>
#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

View file

@ -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) {