推送通知:didFailToRegister 和 didRegister 委托都没有调用 [英] push notification : both didFailToRegister and didRegister delegate not calling

查看:29
本文介绍了推送通知:didFailToRegister 和 didRegister 委托都没有调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个支持推送通知的应用程序
我正在按照所有步骤操作.

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

它在模拟器上出错

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  

我的代码:

- (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);
}

推荐答案

已为我解决:

设备中,转到:

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

这篇关于推送通知:didFailToRegister 和 didRegister 委托都没有调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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