我正在调度计时器,并向用户发送一些关于某些数据的本地通知,例如,如果附近有商店的话。
func configureNotification(shop: Shop) {
let notification = UILocalNotification()
notification.fireDate = NSDate(timeIntervalSinceNow: 0)
notification.alertBody = "There is a store \(shop.name) near!"//Localized().near_shop_string + shopName
notification.alertAction = "Swipe to see offer!"//Localized().swipe_to_see_string
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}当应用程序在后台运行时,如果在用户坐标附近有某个商店,就会有一个本地通知。
例如,收到了三个关于不同商店的本地通知,用户可以从第二个商店中滑动程序并使应用程序活动起来。
问题是,要从applicationDidBecomeActive启动的特定通知(某些launcOptions )中识别出来自服务器的推送通知?有什么解决办法吗?
发布于 2016-08-22 10:45:53
您需要在didReceiveLocalNotification委托方法中处理它
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!) {
// do your jobs here
}notification param将包含每个通知的信息。
另外,launchOptions有一个包含通知的键UIApplicationLaunchOptionsLocalNotificationKey。
你可以像
let localNotification:UILocalNotification = launchOptions.objectForKey(UIApplicationLaunchOptionsLocalNotificationKey)https://stackoverflow.com/questions/39077463
复制相似问题