Canceling banner notification in iOS8 not working

My title may not accurately reflect my question, so I'm sorry. I've been looking for a solution to create this level of functionality, but I can't seem to find one.

I am creating a VoIP application for iOS 8. When the user receives a call, I show a notification with a 12 second ringtone. While this notification is running, if the call is disconnected, I want the incoming call notification to disappear and display the missed call notification immediately. This level of functionality is possible because Viber does it.

I am currently sending a silent push notification when an incoming call is available. This is my payload ...

aps = {
        "content-available" = 1;
      };
      category = INCOMING;
      from = "+15555554220";

      

After receiving a silent press, I create a local notification like this ...

if ([userInfo[@"category"] isEqualToString:@"INCOMING"]) {
                NSLog(@"application: didReceiveRemoteNotification:  fetchCompletionHandler: Incoming Call Notification Received");

                NSLog(@"application: didReceiveRemoteNotification:  fetchCompletionHandler: Sending Local Notification For Incoming Call");

                // Get Caller Contact Info
                NSDictionary *contact = [self findContactInfoForNumber:userInfo[@"from"]];

                NSString *message = [NSString stringWithFormat:@"Incoming Call: %@",userInfo[@"from"]];

                if (contact != nil) {
                    message = [NSString stringWithFormat:@"Incoming Call: %@ %@",contact[@"firstName"],contact[@"lastName"]];
                }

                UILocalNotification *notification = [[UILocalNotification alloc] init];
                NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithObject:@"Incoming Call" forKey:@"type"];
                notification.userInfo = infoDict;
                notification.category = @"INCOMING_CALL_CATEGORY";
                notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
                notification.alertBody = message;
                notification.timeZone = [NSTimeZone defaultTimeZone];
                notification.soundName = @"ring.m4a";

                [[UIApplication sharedApplication] scheduleLocalNotification:notification];

            }

      

Then, once the call is disconnected, I send another silent push notification for the missed call ...

aps = {
        "content-available" = 1;
      };
      category = MISSED;

      

Upon receipt, I cancel all local notifications like this ...

if ([userInfo[@"category"] isEqualToString:@"MISSED"]) {
     NSLog(@"application: didReceiveRemoteNotification:  fetchCompletionHandler: Missed Call Notification Received");
     [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
     [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

      

The problem I am running into is that on the lock screen it behaves exactly the way I want it to. I receive an incoming call notification and when the caller hangs up, that notification immediately disappears from the notification center and a missed call notification appears instead. However, when the phone is on the home screen. The banner is displayed and then the entire ringtone is played and then the missed call is displayed. Does anyone know the reason why this is happening? Does anyone have a solution to achieve this level of functionality? As I said, the Vider app is a prime example of what I want my app to do.

Thank you in advance.

+3


source to share





All Articles