推送通知在iOS 9及更高版本中不起作用

时间:2016-10-19 14:28:04

标签: ios azure push-notification notifications

iOS中的推送通知存在问题。我已经跟进了this教程。 iOS 9及更高版本尚未收到推送通知。

这是注册和管理通知的代码:

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound |
                                                UIUserNotificationTypeAlert | UIUserNotificationTypeBadge categories:nil];

        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }else{
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
    }

    return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
    SBNotificationHub* hub = [[SBNotificationHub alloc] initWithConnectionString:HUBLISTENACCESS
                                                             notificationHubPath:HUBNAME];

    [hub registerNativeWithDeviceToken:deviceToken tags:nil completion:^(NSError* error) {
        if (error != nil) {
            NSLog(@"Error registering for notifications: %@", error);
            [self MessageBox:@"Registration Error" message:[error localizedDescription]];
        }
        else {
            NSLog(@"Registering for notifications OK");
            [self MessageBox:@"Registration Status" message:@"Registered"];
        }
    }];

}

- (void)application:(UIApplication*)application
    didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
    [self MessageBox:@"Registration Status" message:[error localizedDescription]];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {
    NSLog(@"%@", userInfo);

    [self MessageBox:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"] message:[[userInfo objectForKey:@"aps"] valueForKey:@"alert"]];
}

-(void)MessageBox:(NSString *)title message:(NSString *)messageText
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:messageText delegate:self
                                          cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
}

我已在功能

中检查了推送通知和远程通知(在Backgorund模式下)

提前致谢

0 个答案:

没有答案