2016-05-22 99 views
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上没有通知显示。 任何想法,为什么这是?

+0

您可以按照[PubNub移动推送故障排除指南](https://www.pubnub.com/knowledge-base/discussion/1127/how-can-i-troubleshoot-my-push-notification-issues)并提供有价值的数据点,如果你仍然无法确定问题? –

+0

故障排除指南有帮助吗? –

+0

@CraigConover仍在看它。可能会使用Firebase,因为它看起来像还具有推送通知功能。不知道该怎么办 – Erik

回答

0

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

+0

我正在听我的真实iPhone 5S上的通知,但从模拟器发送它。 – Erik