更新到 IOS 8 和 Xcode 6 后本地通知不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26101395/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Local Notification not working since updating to IOS 8 and Xcode 6
提问by burrGGG
Has anyone else had problems with local notifications since updating to IOS 8 and Xcode 6? I have my application which was running fine and the notification.firdate
was set from date picker and working fine, notification.alertBody
showed up fine. Now i've updated it doesn't work. I've added break points and my firedate has a value stored in it. Can anyone please help me?
自从更新到 IOS 8 和 Xcode 6 以来,有没有其他人遇到过本地通知问题?我的应用程序运行良好,并且notification.firdate
从日期选择器设置并且工作正常,notification.alertBody
显示正常。现在我更新了它不起作用。我添加了断点,并且我的 firedate 中存储了一个值。谁能帮帮我吗?
回答by Sandro Machado
You need to update your code to be able to receive notifications in iOS8. More info here.
您需要更新代码才能在 iOS8 中接收通知。更多信息在这里。
Objective-C code:
目标-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;
}
Swift Code:
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
}
回答by Harshal Wani
In order to receive Local NSNotification, follow the below steps:
为了接收本地 NSNotification,请按照以下步骤操作:
Add code into your
appDelegate.h
indidFinishLaunchingWithOptions
methodif ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; }
将代码添加到您的
appDelegate.h
indidFinishLaunchingWithOptions
方法中if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; }