我正在使用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看到一些设备日志,证明已经调用了远程通知并在SDK中运行代码行:[[WalkieTalkie sharedWT].delegate onPushMessage:content];
。但是演示应用程序只显示没有,没有反应。我是否将代理代码放在了错误的地方?或者只是SDK处于活动状态且应用程序仍在后台?我不知道,请给我一些建议,非常感谢!