From 8d694d22ad421236821497531ec0b8024157341e Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Thu, 17 Dec 2015 16:03:19 +0100 Subject: [PATCH] Allow to show messages in notifications, and answer it inline in iOS9. --- Classes/LinphoneAppDelegate.h | 1 + Classes/LinphoneAppDelegate.m | 27 ++++++++++++------- Classes/LinphoneManager.m | 4 +++ Classes/SettingsView.m | 6 +++++ Settings/InAppSettings.bundle/Advanced.plist | 10 +++++++ .../en.lproj/Advanced.strings | 1 + 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index a0ec499e1..edda21b1b 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -30,6 +30,7 @@ } - (void)processRemoteNotification:(NSDictionary*)userInfo; +- (void)registerForNotifications:(UIApplication *)app; @property (nonatomic, retain) UIAlertView *waitingIndicator; @property (nonatomic, retain) NSString *configURL; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 44cb59356..20562b87c 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -127,7 +127,8 @@ mark_read.authenticationRequired = NO; NSArray *actions; - if ([[UIDevice.currentDevice systemVersion] floatValue] < 9) { + if ([[UIDevice.currentDevice systemVersion] floatValue] < 9 || + [LinphoneManager.instance lpConfigBoolForKey:@"show_msg_in_notif"] == NO) { actions = @[ mark_read, reply ]; } else { // iOS 9 allows for inline reply. We don't propose mark_read in this case @@ -167,14 +168,8 @@ return localRingNotifAction; } -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - - UIApplication *app = [UIApplication sharedApplication]; - UIApplicationState state = app.applicationState; - - LinphoneManager *instance = LinphoneManager.instance; - BOOL background_mode = [instance lpConfigBoolForKey:@"backgroundmode_preference"]; - BOOL start_at_boot = [instance lpConfigBoolForKey:@"start_at_boot_preference"]; +- (void)registerForNotifications:(UIApplication *)app { + LinphoneManager *instance = [LinphoneManager instance]; if ([app respondsToSelector:@selector(registerUserNotificationSettings:)]) { /* iOS8 notifications can be actioned! Awesome: */ @@ -191,12 +186,25 @@ [app registerForRemoteNotifications]; } } else { + /* iOS7 and below */ if (!instance.isTesting) { NSUInteger notifTypes = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge; [app registerForRemoteNotificationTypes:notifTypes]; } } +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + UIApplication *app = [UIApplication sharedApplication]; + UIApplicationState state = app.applicationState; + + LinphoneManager *instance = [LinphoneManager instance]; + BOOL background_mode = [instance lpConfigBoolForKey:@"backgroundmode_preference"]; + BOOL start_at_boot = [instance lpConfigBoolForKey:@"start_at_boot_preference"]; + + [self registerForNotifications:app]; if (state == UIApplicationStateBackground) { // we've been woken up directly to background; @@ -461,6 +469,7 @@ if (room) { LinphoneChatMessage *msg = linphone_chat_room_create_message(room, replyText.UTF8String); linphone_chat_room_send_chat_message(room, msg); + linphone_chat_room_mark_as_read(room); } } } diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 3817a54b8..4b1a80d08 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -911,6 +911,10 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, const char NSString *callID = [NSString stringWithUTF8String:linphone_chat_message_get_custom_header(msg, "Call-ID")]; const LinphoneAddress *remoteAddress = linphone_chat_message_get_from_address(msg); NSString *from = [FastAddressBook displayNameForAddress:remoteAddress]; + const char *chat = linphone_chat_message_get_text(msg); + if (chat == NULL) + chat = ""; + char *c_address = linphone_address_as_string_uri_only(remoteAddress); NSString *remote_uri = [NSString stringWithUTF8String:c_address]; diff --git a/Classes/SettingsView.m b/Classes/SettingsView.m index 98cf47fe5..fdf9607bc 100644 --- a/Classes/SettingsView.m +++ b/Classes/SettingsView.m @@ -19,6 +19,7 @@ #import "SettingsView.h" #import "LinphoneManager.h" +#import "LinphoneAppDelegate.h" #import "PhoneMainView.h" #import "Utils.h" @@ -432,6 +433,11 @@ static UICompositeViewDescription *compositeDescription = nil; removeFromHiddenKeys = [video_preset isEqualToString:@"custom"]; [keys addObject:@"video_preferred_fps_preference"]; [keys addObject:@"download_bandwidth_preference"]; + } else if ([notif.object isEqualToString:@"show_msg_in_notif"]) { + // 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]; } for (NSString *key in keys) { diff --git a/Settings/InAppSettings.bundle/Advanced.plist b/Settings/InAppSettings.bundle/Advanced.plist index 2e3e28ca1..b1a30d9a5 100644 --- a/Settings/InAppSettings.bundle/Advanced.plist +++ b/Settings/InAppSettings.bundle/Advanced.plist @@ -102,6 +102,16 @@ Type PSToggleSwitchSpecifier + + DefaultValue + + Key + show_msg_in_notif + Title + Show message in notification + Type + PSToggleSwitchSpecifier + DefaultValue diff --git a/Settings/InAppSettings.bundle/en.lproj/Advanced.strings b/Settings/InAppSettings.bundle/en.lproj/Advanced.strings index 0c2e24ca3..6e8c6d2e2 100644 --- a/Settings/InAppSettings.bundle/en.lproj/Advanced.strings +++ b/Settings/InAppSettings.bundle/en.lproj/Advanced.strings @@ -14,3 +14,4 @@ "Username" = "Username"; "File sharing" = "File sharing"; "Server URL" = "Server URL"; +"Show message in notification" = "Show message in notification"; \ No newline at end of file