【发布时间】:2015-09-16 08:28:12
【问题描述】:
如果用户已强制退出应用程序(通过在多任务界面中向上滑动)并且设备已重新启动,我无法获得重新启动应用程序的 voip pushkit 通知。
但是,我可以让 voip pushkit 通知在以下情况下工作:
应用程序被强制退出,然后推送工具包通知到达。该应用程序将立即重新启动。在这种情况下,标准推送通知无法唤醒应用。
应用程序在后台/挂起,设备已重新启动。感谢 Voip 模式,应用程序将在设备重新启动时重新启动(我可以在 Xcode Activity Monitor 中看到该过程)。这里需要一个技巧来正确处理 Pushkit 通知,在 http://blog.biokoda.com/post/114315188985/ios-and-pushkit 中描述了这些术语“在初始化 PushKit 之前启动后台任务。收到 PushKit 令牌后完成此任务”
当结合这两者(设备重启和应用程序强制退出)时,pushkit 通知似乎不会重新启动应用程序。此外,在 Xcode 中查看设备日志时,我没有从 apsd 收到任何日志,表明通知已由系统处理。
这是我的代码:
@implementation AppDelegate
{
UIBackgroundTaskIdentifier bgTask;
}
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while (true) {
;
}
});
// Initialize pushkit
PKPushRegistry *pushRegistry =
[[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
return YES;
}
- (void)pushRegistry:(PKPushRegistry *)registry
didUpdatePushCredentials:(PKPushCredentials *)credentials
forType:(NSString *)type{
UIApplication* app = [UIApplication sharedApplication];
[app endBackgroundTask:bgTask];
// ... more code to read the token ...
}
- (void)pushRegistry:(PKPushRegistry *)registry
didReceiveIncomingPushWithPayload:(PKPushPayload *)payload
forType:(NSString *)type {
// ... logging to check if notification is received ...
}
我还在后台模式下启用了“IP 语音”和“远程通知”。
我知道像 Whatsapp 这样的其他应用能够在这种情况下重新启动,所以我不明白我做错了什么。
在相关说明中,执行以下操作无济于事 1) 强制退出 2) 发送 pushkit 通知 - 将收到该通知 3) 重新启动。应用不会重新启动,新的推送通知也不会重新启动。
【问题讨论】:
-
@sahara108 和我自己也有这个问题。我已经直接问过苹果,所以如果他们在其他人弄清楚之前回答,我会在这里发布答案。您还提到您的 WhatsApp 等可以重新启动,但它们会完全重新启动吗?在我们的调查中,应用程序重新启动但没有完全启动。他们的日志记录被过早地截断(看起来像是操作系统被杀)。
-
通过查看活动监视器中正在启动的进程,我确定应用程序已重新启动。
标签: ios ios8 notifications apple-push-notifications voip