如何让应用程序在后台或不在后台时都知道未接来电运行
How to let the app aware of missed calls when in background or not running
我使用的 Sinch SDK 版本是:3.7.1-0313526 - Xcode 6.3 - IOS SDK 8.3 我想知道什么是让应用知道的最佳方式有一个 未接来电,无论它是否在后台 运行 所以我可以更新 UI 和未接来电徽章。
我正在寻找的行为非常标准。应用程序是否处于后台 运行,来电。如果是未接来电,应用徽章将更新,显示的通知将更改为 'Missed call'。与所有其他通话应用程序一样。
到目前为止,我已经尝试了以下方法来尝试从 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 秒)点击通知提醒
应用程序将打开,然后显示未接来电提醒
如果用户在等待几秒钟后没有点击通知提醒,或者只是忽略通知提醒,只是通过点击应用程序图标打开应用程序,应用程序永远不会知道有未接来电,因为“[[result callResult] isTimeout] 不会变为真”,因此应用永远不会更新 UI,用户永远不会知道有未接来电。
为了全面披露,我使用的 Parse SDK 版本是 1.7.4,并且只添加了推送通知作为通知客户端新呼叫的一种方式:
#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];
}
}
非常感谢您的帮助。
当您收到以无人接听为由结束的呼叫时,您可以通过解析发送推送。
我使用的 Sinch SDK 版本是:3.7.1-0313526 - Xcode 6.3 - IOS SDK 8.3 我想知道什么是让应用知道的最佳方式有一个 未接来电,无论它是否在后台 运行 所以我可以更新 UI 和未接来电徽章。
我正在寻找的行为非常标准。应用程序是否处于后台 运行,来电。如果是未接来电,应用徽章将更新,显示的通知将更改为 'Missed call'。与所有其他通话应用程序一样。
到目前为止,我已经尝试了以下方法来尝试从 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 秒)点击通知提醒
应用程序将打开,然后显示未接来电提醒
如果用户在等待几秒钟后没有点击通知提醒,或者只是忽略通知提醒,只是通过点击应用程序图标打开应用程序,应用程序永远不会知道有未接来电,因为“[[result callResult] isTimeout] 不会变为真”,因此应用永远不会更新 UI,用户永远不会知道有未接来电。
为了全面披露,我使用的 Parse SDK 版本是 1.7.4,并且只添加了推送通知作为通知客户端新呼叫的一种方式:
#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];
}
}
非常感谢您的帮助。
当您收到以无人接听为由结束的呼叫时,您可以通过解析发送推送。