1

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

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

即使我在 didfinishlaunch 中添加了以下代码,也没有调用

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

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

4

1 回答 1

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

更新

在设备中,转到 Settings->Notifications->YourApp->Enable_Notifications

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

iOS 在应用程序中注册推送通知

推送通知的“查看”委托

推送通知委托回调没有被调用

推送通知委托方法问题

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

推送通知代表没有被调用

编辑签 入设置是否有通知未关闭 在此处输入图像描述

于 2012-11-21T06:16:34.780 回答