0
我有了這個代碼在我的AppDelegate的didFinishLaunchingWithOptions:
PubNub推送通知將不會顯示
PNConfiguration *pnConfiguration = [PNConfiguration configurationWithPublishKey:publishKey
subscribeKey:subscribeKey];
self.client = [PubNub clientWithConfiguration:pnConfiguration];
/* push notifications */
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
除了這兩種方法設置:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"deviceToken: %@", deviceToken);
[[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"DeviceToken"];
[self.client addPushNotificationsOnChannels:@[@"apns"] withDevicePushToken:deviceToken andCompletion:^(PNAcknowledgmentStatus *status) {
}];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"%s with error: %@", __PRETTY_FUNCTION__, error);
}
我已經添加了對權利我的應用ID,並將證書上傳到PubNub控制檯here
這裏是我發送推送通知的代碼:
[self.client publish:nil toChannel:@"apns" mobilePushPayload: @{@"aps": @{@"alert":message}}
withCompletion:^(PNPublishStatus *status) {
// Check whether request successfully completed or not.
// if (status.isError) // Handle modification error.
// Check 'category' property to find out possible issue because
// of which request did fail. Request can be resent using: [status retry];
}];
但是,從iOS模擬器發佈時,我的iPhone上沒有通知顯示。 任何想法,爲什麼這是?
您可以按照[PubNub移動推送故障排除指南](https://www.pubnub.com/knowledge-base/discussion/1127/how-can-i-troubleshoot-my-push-notification-issues)並提供有價值的數據點,如果你仍然無法確定問題? –
故障排除指南有幫助嗎? –
@CraigConover仍在看它。可能會使用Firebase,因爲它看起來像還具有推送通知功能。不知道該怎麼辦 – Erik