[英]PubNub push notifications won't display
我已經在AppDelegate的didFinishLaunchingWithOptions:
設置了以下代碼didFinishLaunchingWithOptions:
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控制台這里
這是我發送推送通知的代碼:
[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上沒有顯示通知。 知道為什么會這樣嗎?
推送通知不適用於模擬器。 您將需要在真實設備上進行測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.