Я разрабатываю SDK для iOS с помощью VoIP PushKit. А вот код в SDK, когда получить толчок уведомленияVoIP Push не работает для демонстрации SDK для iOS
- (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 активен, и приложение все еще находится в фоновом режиме? Я понятия не имею, пожалуйста, дайте мне несколько советов, спасибо большое!
Это сработало? – Hasya