更新到IOS 8和Xcode 6后,本地通知无法正常工作

bur*_*GGG 26 iphone xcode objective-c ios xcode6

自更新到IOS 8和Xcode 6后,是否有其他人遇到本地通知问题?我的应用程序运行正常,并且notification.firdate从日期选择器设置并且工作正常,notification.alertBody 显示正常.现在我已经更新它不起作用.我添加了断点,我的被激活的值存储在其中.谁能帮帮我吗?

San*_*ado 68

您需要更新代码才能在iOS8中接收通知.更多信息在这里.

Objective-C代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
    }
    // Override point for customization after application launch.
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

SWIFT代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
//registering for sending user various kinds of notifications
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound|UIUserNotificationType.Alert |UIUserNotificationType.Badge, categories: nil)   
// Override point for customization after application launch.     
return true
}
Run Code Online (Sandbox Code Playgroud)

  • @burrGGG Er,这是Objective C代码. (12认同)