我使用的是Sinch SDK版本:3.7.1-0313526 - 使用Xcode 6.3 - IOS SDK 8.3我想知道什么是让应用知道未接来电的最佳方式它是在后台运行或未运行所以我可以更新未接来电的用户界面和徽章。
我正在寻找的行为非常标准。该应用程序处于后台或未运行,呼叫到达。如果是未接来电,则会更新应用徽章,并且显示的通知将更改为“未接来电”#39;像所有其他调用应用程序一样。
到目前为止,我已尝试以下方法尝试接听来自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];
}
}
我从以下方法调用上述方法:
#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];
}
不幸的是,这似乎只适用于以下情况:
用户需要在几秒钟后(大约10秒钟)点击通知提醒
该应用将会打开,然后会显示未接来电的提示
如果用户在等待几秒钟后没有点击通知提醒,或者只是忽略通知提醒,只需点按应用图标即可打开应用,该应用将永远不会知道有未接来电&#34; [[result callResult] isTimeout]不会变为真&#34;因此该应用永远不会更新用户界面,用户永远不会知道有未接来电。
对于完全披露,我使用的是Parse SDK版本是1.7.4并且只添加了Push通知作为通知客户端新呼叫的方法:
#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];
}
}
非常感谢您提前寻求帮助。
答案 0 :(得分:0)
当你收到calldid end并且理由noanswer时,你可以通过解析发送推送。