我无法启用推送通知。
使用此代码我尝试启用通知:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
return YES;
}
它不起作用,所以我在行
中添加了一个断点[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
但似乎这部分代码永远不会执行。
为什么这不起作用?
答案 0 :(得分:7)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
这应该在您的UIApplicationDelegate
中实施,而不是在UIViewController
中实施。如果你在UIViewController
中拥有它,它将永远不会被调用。从那里取出代码并将其放在UIApplicationDelegate
中。