我正在使用 Push Kit 框架开发一个 VoIP 应用,但是遇到了一些与远程通知相关的问题。
问题
1) 当设备关闭时发送的通知消息会被永久丢失。
2) 设备重新启动后,除非再次启动应用程序,否则无法接收到推送通知消息。
我已经启用了 VoIP over IP、后台获取、远程通知功能,并检查是否存在任何通知消息。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary* payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (payload) {
// process the payload here
NSLog(@"There are some notifications are available for processing");
}
}
我已经覆盖了以下方法
//PushKit Notification Alerts methods
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{
if([credentials.token length] == 0) {
NSLog(@"voip token NULL");
return;
}
NSLog(@"PushCredentials: %@", credentials.token);
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type{
[self showLocalNotification:[[payload dictionaryPayload] valueForKey:@"data"]];
}
当应用程序在前台运行时,它可以正常工作;当应用程序进入后台时,它也可以接收到消息。即使用户强制退出应用程序,它也能接收到消息。
测试平台操作系统版本:iOS 8.1及以上设备:iPhone 5C、iPhone 5S、iPhone 6和iPhone 6+。