Gme*_*er4 5 iphone apple-push-notifications ios apns-php swift
在决定是否向用户发送本地通知之前,我正在向我的应用发送静默推送通知,然后处理推送通知的内容.但是,在收到无声通知后,我无法从应用程序发出本地通知.
这是触发静默通知后appdelegate中的代码:
func application(application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler handler: (UIBackgroundFetchResult) -> Void) {
println("Did receive remote with completion handler")
var localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "view broadcast messages"
localNotification.alertBody = "Hello"
localNotification.fireDate = NSDate(timeIntervalSinceNow: 0)
localNotification.soundName = UILocalNotificationDefaultSoundName;
application.scheduleLocalNotification(localNotification)
handler(UIBackgroundFetchResult.NewData)
}
Run Code Online (Sandbox Code Playgroud)
但是,本地通知永远不会触发.
我启用了位置更新,后台提取和远程通知功能.
此外,当我的应用程序处于其后台状态时,它会侦听位置更新,然后在特定情况下使用本地通知向用户发出警报 - 这类似于代码.
那么为什么本地通知不会从中发出didReceiveRemoteNotification?
谢谢
好的,我想通了,
application.scheduleLocalNotification(localNotification)
Run Code Online (Sandbox Code Playgroud)
本来应该
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
Run Code Online (Sandbox Code Playgroud)
希望这有助于某人!
| 归档时间: |
|
| 查看次数: |
4085 次 |
| 最近记录: |