3

我无法启用推送通知。

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

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

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

    return YES;
}

它不起作用,所以我在该行中添加了一个断点

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

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

为什么这不起作用?

4

1 回答 1

8

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

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

于 2012-12-14T12:10:32.777 回答