Search code examples
iosobjective-csinch

How to let the app aware of missed calls when in background or not running


I am using Sinch SDK version is: 3.7.1-0313526 - with Xcode 6.3 - IOS SDK 8.3 and I would like to know what is the best way to let the app know that there was a missed call when it was in background or not running so I can update UI and badges for missed calls.

The behaviour which I am looking for it's pretty standard. The app is in background or not running, a call arrives. If it is a missed call, the app badge will be update and the notification shown will change to 'Missed call'. Like all the other calling apps.

So far I have tried the following to try to get the missed call from sinch:

- (void)handleRemoteNotification:(NSDictionary *)userInfo {

// Extract the Sinch-specific payload from the Apple Remote Push Notification
NSString* SIN = [userInfo valueForKey:@"sin"];

// Get previously initiated Sinch client
id<SINClient> client = _client;

id<SINNotificationResult> result = [client relayRemotePushNotificationPayload: SIN];

if ([result isCall] && [[result callResult] isTimedOut]) {

    //Let set the badge number

    [self setTheCallBadgeValue];

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Missed call"
                          message:[NSString stringWithFormat:@"Missed call from %@", callerName]
                          delegate:nil
                          cancelButtonTitle:nil
                          otherButtonTitles:@"OK", nil];
    [alert show];
}   

}

I call the above method from:

#pragma mark - SINManagedPushDelegate

- (void)managedPush:(id<SINManagedPush>)unused
didReceiveIncomingPushWithPayload:(NSDictionary *)payload
        forType:(NSString *)pushType {
   //  NSLog(@"Incoming push - This is the payload: %@", payload);

    [self handleRemoteNotification:payload];

}

Unfortunately, that only seems to work on the following cases:

  1. User needs to tap on the notification alert after a few second (around 10s)

  2. The app will open, then it will show the alert for missed call

If user doesn't tap on the notification alert after waiting a few seconds or just ignore the notification alert and just open the app by tapping on the app icon, the app will never know that there was a missed call as "[[result callResult] isTimeout] will not become true", therefore the app will never update UI and the user won't never know that there was a missed call.

For full disclosure, I am using Parse SDK version is 1.7.4 and only added Push notification as a mean to inform the client of new calls:

  #pragma Mark - Let Instantiate Sinch!

- (void)initSinchClientWithUserId:(NSString *)userId {

 //  NSLog(@"Sinch client has started with user id: %@", userId);
   if (!_client) {
    _client = [Sinch clientWithApplicationKey: SINCH_APPLICATION_KEY
                            applicationSecret: SINCH_APPLICATION_SECRET
                              environmentHost: SINCH_ENVIRONMENT_HOST
                                       userId:userId];

    _client.delegate = self;
    _client.callClient.delegate = self;
    [_client setSupportCalling:YES];
    [_client enableManagedPushNotifications];

    [_client setSupportActiveConnectionInBackground:NO];

    [_client start];
   // [_client startListeningOnActiveConnection];

    NSString *currUsrName = [userDefaults objectForKey:@"currentUserFullName"];

    [_client setPushNotificationDisplayName:currUsrName];
}
}

Thank you very much in advance for any help.


Solution

  • You could send a push via parse when you recieve calldid end with reason noanswer.