2

プッシュ通知をサポートするアプリケーションを作成しています
すべての手順を実行しています。プッシュ通知:didFailToRegisterとdidRegisterデリゲートはどちらも呼び出しません。

それはシミュレータ

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

答えて

4

デバイス、に行く:

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

Push notificationiPhone's Simulatorでは動作しません。

端末で確認してください。

シミュレータ に動作しますが、警告の乗り心地を取得したい場合は、ここでシミュレータとデバイスの両方で を動作するコードではありませんでしょう@kalyanプッシュ通知で述べたよう
0

とiOS7と(TARGET_IPHONE_SIMULATORをチェック) iOS8(registerUserNotificationSettingsを確認してください)

- (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 
} 
関連する問題