Repeat Call notifications if option is set + end of repeat when notif handeld or call ended

This commit is contained in:
REIS Benjamin 2016-09-28 16:27:07 +02:00
parent fe600f3f7b
commit a81a229086
2 changed files with 86 additions and 8 deletions

View file

@ -533,10 +533,17 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
LOGD(@"UN : response recieved");
LOGD(response.description);
LinphoneCall* call = linphone_core_get_current_call(LC);
if (call) {
LinphoneCallAppData *data = (__bridge LinphoneCallAppData *)linphone_call_get_user_data(call);
if (data->timer) {
[data->timer invalidate];
data->timer = nil;
}
}
if ([response.actionIdentifier isEqual:@"Answer"]) {
[LinphoneManager.instance acceptCallForCallId:[response.notification.request.content.userInfo objectForKey:@"callId"]];
} else if ([response.actionIdentifier isEqual:@"Decline"]) {
LinphoneCall* call = linphone_core_get_current_call(LC);
linphone_core_decline_call(LC, call, LinphoneReasonDeclined);
} else if ([response.actionIdentifier isEqual:@"Reply"]) {
LinphoneCore *lc = [LinphoneManager getLc];
@ -564,7 +571,9 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
if ([response.notification.request.content.categoryIdentifier isEqual:@"call_cat"]) {
[LinphoneManager.instance acceptCallForCallId:[response.notification.request.content.userInfo objectForKey:@"callId"]];
} else if ([response.notification.request.content.categoryIdentifier isEqual:@"msg_cat"]) {
[PhoneMainView.instance changeCurrentView:ChatsListView.compositeViewDescription];
} else { //Missed call
[PhoneMainView.instance changeCurrentView:HistoryListView.compositeViewDescription];
}
}
}
@ -575,7 +584,16 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
handleActionWithIdentifier:(NSString *)identifier
forLocalNotification:(UILocalNotification *)notification
completionHandler:(void (^)())completionHandler {
LOGI(@"%@", NSStringFromSelector(_cmd));
LinphoneCall* call = linphone_core_get_current_call(LC);
if (call) {
LinphoneCallAppData *data = (__bridge LinphoneCallAppData *)linphone_call_get_user_data(call);
if (data->timer) {
[data->timer invalidate];
data->timer = nil;
}
}
LOGI(@"%@", NSStringFromSelector(_cmd));
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) {
LOGI(@"%@", NSStringFromSelector(_cmd));
if ([notification.category isEqualToString:@"incoming_call"]) {
@ -612,7 +630,15 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
forLocalNotification:(UILocalNotification *)notification
withResponseInfo:(NSDictionary *)responseInfo
completionHandler:(void (^)())completionHandler {
LinphoneCall* call = linphone_core_get_current_call(LC);
if (call) {
LinphoneCallAppData *data = (__bridge LinphoneCallAppData *)linphone_call_get_user_data(call);
if (data->timer) {
[data->timer invalidate];
data->timer = nil;
}
}
if ([notification.category isEqualToString:@"incoming_call"]) {
if ([identifier isEqualToString:@"answer"]) {
// use the standard handler

View file

@ -617,6 +617,22 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char
}
}
- (void)userNotifContinue:(NSTimer *)timer {
UNNotificationContent *content = [timer userInfo];
if (content) {
LOGI(@"cancelling/presenting user notif");
UNNotificationRequest *req = [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:req withCompletionHandler:^(NSError * _Nullable error) {
// Enable or disable features based on authorization.
if (error) {
LOGD(@"Error while adding notification request :");
LOGD(error.description);
}
}];
}
}
- (void)onCall:(LinphoneCall *)call StateChanged:(LinphoneCallState)state withMessage:(const char *)message {
// Handling wrapper
LinphoneCallAppData *data = (__bridge LinphoneCallAppData *)linphone_call_get_user_data(call);
@ -689,7 +705,8 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char
[[UIApplication sharedApplication] registerUserNotificationSettings:set];
data->notification = [[UILocalNotification alloc] init];
if (data->notification) {
// iOS8 doesn't need the timer trick for the local notification.
// iOS8 doesn't need the timer trick for the local notification.
data->notification.category = @"incoming_call";
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8 &&
[self lpConfigBoolForKey:@"repeat_call_notification"] == NO) {
NSString *ring =
@ -697,7 +714,6 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char
?: [LinphoneManager bundleFile:@"notes_of_the_optimistic.caf"])
.lastPathComponent;
data->notification.soundName = ring;
data->notification.category = @"incoming_call";
} else {
data->notification.soundName = @"shortring.caf";
data->timer = [NSTimer scheduledTimerWithTimeInterval:5
@ -734,10 +750,16 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.title = @"Incoming call";
content.body = address;
content.sound = [UNNotificationSound soundNamed:@"shortring.caf"];
content.sound = [UNNotificationSound soundNamed:@"notes_of_the_optimistic.caf"];
content.categoryIdentifier = @"call_cat";
content.userInfo = @{@"callId" : callId};
if ([self lpConfigBoolForKey:@"repeat_call_notification"] == YES) {
data->timer = [NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:@selector(userNotifContinue:)
userInfo:content
repeats:TRUE];
}
UNNotificationRequest *req = [UNNotificationRequest requestWithIdentifier:@"call_request" content:content trigger:NULL];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:req withCompletionHandler:^(NSError * _Nullable error) {
// Enable or disable features based on authorization.
@ -746,6 +768,18 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char
LOGD(error.description);
}
}];
if (!incallBgTask) {
incallBgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
LOGW(@"Call cannot ring any more, too late");
[[UIApplication sharedApplication] endBackgroundTask:incallBgTask];
incallBgTask = 0;
}];
if (data->timer) {
[[NSRunLoop currentRunLoop] addTimer:data->timer forMode:NSRunLoopCommonModes];
}
}
}
}
@ -768,6 +802,24 @@ static void linphone_iphone_display_status(struct _LinphoneCore *lc, const char
/*IOS specific*/
linphone_core_start_dtmf_stream(theLinphoneCore);
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max && ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)) {
if (data->timer) {
[data->timer invalidate];
data->timer = nil;
}
LinphoneCallLog *UNlog = linphone_call_get_call_log(call);
if (UNlog == NULL || linphone_call_log_get_status(UNlog) == LinphoneCallMissed) {
UNMutableNotificationContent* missed_content = [[UNMutableNotificationContent alloc] init];
missed_content.title = @"Missed call";
missed_content.body = address;
UNNotificationRequest *missed_req = [UNNotificationRequest requestWithIdentifier:@"call_request" content:missed_content trigger:NULL];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:missed_req withCompletionHandler:^(NSError * _Nullable error) {
// Enable or disable features based on authorization.
if (error) {
LOGD(@"Error while adding notification request :");
LOGD(error.description);
}
}];
}
linphone_core_set_network_reachable(LC, FALSE);
LinphoneManager.instance.connectivity = none;