【发布时间】:2016-05-22 12:09:49
【问题描述】:
我已经在我的 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,并将证书上传到 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 mobile push troubleshooting guide here 并提供有价值的数据点?
-
故障排除指南有帮助吗?
-
@CraigConover 还在看。可能正在使用 Firebase,因为它们看起来也具有推送通知功能。还不确定要做什么
-
他们确实像许多其他供应商一样提供推送通知,但 PubNub 和 Firebase 在实时数据流方面有所不同。
标签: ios objective-c pubnub