我正在开发一个使用VoIP PushKit的iOS SDK。以下是SDK中接收推送通知时的代码:
当应用程序处于活动状态时,UIAlertController可以正常工作,但是当我将应用程序杀死并使其处于后台模式时,UILocalNotification永远不会触发。然而,我可以从Xcode中看到一些设备日志,证明远程通知已经被调用并运行了代码行:
- (void)onReceiveMessagecontent:(NSString *)content{
if (content && ![content isEqualToString:@""]) {
if ([[WalkieTalkie sharedWT].delegate respondsToSelector:@selector(onPushMessage:)]) {
[[WalkieTalkie sharedWT].delegate onPushMessage:content];
}
}
}
这是SDK Demo MainViewController.m中的代码,其中将调用委托:
- (void)onPushMessage:(NSString *)messageContent{
NSString *content = [NSString stringWithFormat:@"on recive push message: %@", messageContent];
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"收到推送" message:content preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancelButton];
[self presentViewController:alert animated:YES completion:nil];
} else{
dispatch_async(dispatch_get_main_queue(), ^{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
notification.alertBody = content;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
});
}
}
当应用程序处于活动状态时,UIAlertController可以正常工作,但是当我将应用程序杀死并使其处于后台模式时,UILocalNotification永远不会触发。然而,我可以从Xcode中看到一些设备日志,证明远程通知已经被调用并运行了代码行:
[[WalkieTalkie sharedWT].delegate onPushMessage:content];
在SDK中。但演示应用程序什么也没有显示,没有任何反应。我是否将委托代码放错了地方?还是只有SDK处于活动状态,应用程序仍然在后台?我不知道,请给我一些建议,非常感谢!