推送通知:既didFailToRegister和didRegister代表不是要求 [英] push notification : both didFailToRegister and didRegister delegate not calling

查看:345
本文介绍了推送通知:既didFailToRegister和didRegister代表不是要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建支持推送通知结果的应用
我下面的所有步骤。

这给在模拟器误差

 未能获得令牌,错误:错误域= NSCocoaErrorDomain code = 3010远程通知没有在模拟器支持的UserInfo = 0x5813d20 {NSLocalizedDescription =远程通知,不支持在模拟器}

但在设备,它不调用委托方法

  didFailToRegisterForRemoteNotificationsWithError
didRegisterForRemoteNotificationsWithDeviceToken

我的code:

   - (BOOL)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions
{
    [UIApplication的sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];    的NSLog(@应用程序didFinishLaunchingWithOptions);
    //覆盖点后,应用程序启动定制。    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible]
    返回YES;
} - (无效)应用:(*的UIApplication)的应用didRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)deviceToken {
    的NSLog(@我的令牌是%@,deviceToken);
} - (无效)应用:(*的UIApplication)的应用didFailToRegisterForRemoteNotificationsWithError:(NSError *)错误{
    的NSLog(@未能获得令牌,错误:%@,错误);
} - (无效)应用:(*的UIApplication)的应用didReceiveRemoteNotification:(NSDictionary的*){用户信息
    的NSLog(@接到通知%@,用户信息);
}


解决方案

解决了我:

设备,请访问:

 `设置 - >&通知 -  GT; YourApp-> Enable_Notifications`

I am creating an application which support push notification
I am following all the steps.

It give error on simulator

Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3010 "remote notifications are not supported in the simulator" UserInfo=0x5813d20 {NSLocalizedDescription=remote notifications are not supported in the simulator}

But on device it not calling the delegates methods

didFailToRegisterForRemoteNotificationsWithError  
didRegisterForRemoteNotificationsWithDeviceToken  

My Code :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

    NSLog(@"application didFinishLaunchingWithOptions");
    // Override point for customization after application launch.

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    NSLog(@"My Token is %@",deviceToken);
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
    NSLog(@"Failed to get token, error: %@", error);
}

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

解决方案

Solved for me:

In Device, go to:

`Settings->Notifications->YourApp->Enable_Notifications`

这篇关于推送通知:既didFailToRegister和didRegister代表不是要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆