推送通知不调用该方法

时间:2012-11-21 06:12:24

标签: iphone objective-c ios ipad notifications

我已在我的应用ID中启用了生产推送通知,并使用它创建了配置文件。当我在我的ipad中运行应用程序时,它会询问通知,并且我已收到相应的通知。但问题是方法

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {

没有调用eventhough我已经在didfinishlaunch中添加了以下代码

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

任何想法请帮助我,我现在正在使用ios6。

1 个答案:

答案 0 :(得分:2)

我只是这样恭维: -

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



    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];

}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    self.strToken = [[[[deviceToken description]
                       stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                      stringByReplacingOccurrencesOfString: @">" withString: @""] 
                     stringByReplacingOccurrencesOfString: @" " withString: @""];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

} 




- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive) {
        NSString *cancelTitle = @"Close";
        NSString *showTitle = @"Show";
        NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"myapp name"
                                                            message:message 
                                                           delegate:self 
                                                  cancelButtonTitle:cancelTitle 
                                                  otherButtonTitles:showTitle, nil];
        [alertView show];
        [alertView release];


    } else {
        //Do stuff that you would do if the application was not active
    }
}

<强>更新

  

在设备中,转到设置 - &gt;通知 - &gt; YourApp-&gt; Enable_Notifications

请检查下面的堆栈溢出问题可能对它有帮助

iOS Registering for Push Notifications within Application

Delegate for "View" for Push Notification

Push Notification delegate call backs are not getting called

Push notification delegate method issue

push notification : both didFailToRegister and didRegister delegate not calling

Push Notification Delegates not getting called

修改 签入设置是否有通知未关闭 enter image description here