我正在開發一個帶有VoIP PushKit的iOS SDK。這裏是在SDK代碼收到一個推送通知VoIP推送不適用於iOS SDK演示
- (void)onReceiveMessagecontent:(NSString *)content{
if (content && ![content isEqualToString:@""]) {
if ([[WalkieTalkie sharedWT].delegate respondsToSelector:@selector(onPushMessage:)]) {
[[WalkieTalkie sharedWT].delegate onPushMessage:content];
}
}
}
這裏是SDK演示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處於活動狀態,應用程序仍處於後臺?我不知道,請給我一些建議,非常感謝!
它工作嗎? – Hasya