didFinishLaunchingWithOptions未调用

时间:2012-12-14 10:57:11

标签: iphone xcode4 push-notification

我无法启用推送通知。

使用此代码我尝试启用通知:

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

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

    return YES;
}

它不起作用,所以我在行

中添加了一个断点
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

但似乎这部分代码永远不会执行。

为什么这不起作用?

1 个答案:

答案 0 :(得分:7)

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

这应该在您的UIApplicationDelegate中实施,而不是在UIViewController中实施。如果你在UIViewController中拥有它,它将永远不会被调用。从那里取出代码并将其放在UIApplicationDelegate中。