我正在使用 VoIP PushKit 开发 iOS SDK。这是收到推送通知时SDK中的代码
- (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 处于活动状态而应用程序仍在后台?不太懂,求指教,万分感谢!