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 notification不會iPhone's Simulator工作。

嘗試檢查設備。

0

至於說通過@kalyan推送通知將不會在模擬器 工作,但如果你想獲得的警告騎這裏是既模擬器和設備工作 代碼(檢查TARGET_IPHONE_SIMULATOR) 和iOS7和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 
}