我正在整合PubNub(一种允许设备相互发送消息的服务)到我的iOS应用程序中。
我已按照页面上的说明操作:http://www.pubnub.com/docs/ios-objective-c/mobile-gateway
我已在 AppDelegate.m :
中注册推送通知- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[[UIApplication sharedApplication] registerForRemoteNotifications];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge
|UIUserNotificationTypeSound
|UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
return YES;
}
-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"Application registered for push notifications");
}
-(void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Device failed to register for push:");
}
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"Received push");
}
我正在 ViewController :
中发送通知NSDictionary *push = @{@"pn_apns" :
@{@"aps" : @{
@"alert" : @"notification"
}
}
};
[self.pubNub sendMessage:@"sample" applePushNotification:push toChannel:[PNChannel channelWithName:@"test channel"] compressed:NO withCompletionBlock:^(PNMessageState state, id data) {
switch (state) {
case PNMessageSending:
NSLog(@"sending message");
break;
case PNMessageSendingError:
NSLog(@"error sending message");
break;
case PNMessageSent:
NSLog(@"message sent");
break;
default:
break;
}
}];
我收到消息发送回调,但推送通知未传递到第二个设备。