Alv*_*ese 0 iphone xcode ipad ios swift
这是我的代码.我必须为localNotification添加任何内容.有什么建议.提前致谢.我阅读了很多本地通知教程.我不知道错过了什么.
var localNotifications : UILocalNotification!
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
localNotifications = UILocalNotification()
localNotifications.fireDate = NSDate(timeIntervalSinceNow: 20)
localNotifications.timeZone = NSTimeZone.defaultTimeZone()
localNotifications.alertBody = "Check it out!"
localNotifications.soundName = UILocalNotificationDefaultSoundName
localNotifications.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
UIApplication.sharedApplication().scheduleLocalNotification(localNotifications)
Run Code Online (Sandbox Code Playgroud)
}
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
println("Alvin Notification recieved")
if application.applicationState == UIApplicationState.Active
{
// show alertView
Utilities.sharedInstance.alertThis("Hello", message: "Hey")
}
else if application.applicationState == UIApplicationState.Background
{
UIApplication.sharedApplication().presentLocalNotificationNow(localNotifications)
}
else if application.applicationState == UIApplicationState.Inactive
{
UIApplication.sharedApplication().presentLocalNotificationNow(localNotifications)
}
application.applicationIconBadgeNumber = 0
}
Run Code Online (Sandbox Code Playgroud)
在iOS 8及更高版本中,使用本地或远程通知的应用程序必须注册他们打算提供的通知类型.然后,系统使用户能够限制应用程序显示的通知类型.如果未对您的应用启用任何这些通知类型,系统不会标记图标,显示警报消息或播放警报声音,即使它们已在通知有效负载中指定.
如本指南所示,Apple显示的示例代码为:
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2352 次 |
| 最近记录: |