PubNub推送通知不会显示

时间:2016-05-22 12:09:50

标签: ios objective-c pubnub

我已经在我的AppDelegate 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的权利,并按照here所述将证书上传到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上不会显示任何通知。 知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

推送通知在模拟器上不起作用。您需要在真实设备上进行测试。