Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 推送通知:DidFailtRegister和didRegister委托均未调用_Ios_Iphone_Objective C_Cocoa Touch_Apple Push Notifications - Fatal编程技术网

Ios 推送通知:DidFailtRegister和didRegister委托均未调用

Ios 推送通知:DidFailtRegister和didRegister委托均未调用,ios,iphone,objective-c,cocoa-touch,apple-push-notifications,Ios,Iphone,Objective C,Cocoa Touch,Apple Push Notifications,我正在创建一个支持推送通知的应用程序 我正在遵循所有步骤 在模拟器上给出了误差 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

我正在创建一个支持推送通知的应用程序
我正在遵循所有步骤

在模拟器上给出了误差

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}
但在设备上,它不调用委托方法

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`

推送通知
iPhone模拟器中不起作用


尝试使用设备进行检查。

正如@kalyan所说,推送通知在模拟器中不起作用 但是,如果你想得到警告,这里是代码的工作 同时使用模拟器和设备(检查目标IPHONE模拟器) 以及iOS7和iOS8(检查注册表通知设置)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    #if !TARGET_IPHONE_SIMULATOR
         // New User Notification Settings for iOS8 support
        if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
            UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
            UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types
                                                                                     categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        } else { // for iOS 7
            UIRemoteNotificationType remoteNotificationType = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
             remoteNotificationType];
        }

    #endif
}