【发布时间】:2017-05-23 10:54:17
【问题描述】:
当应用程序位于background 时,我的应用程序首先notification 会在几秒钟后消失,即使用户没有对该notification 采取任何操作。之后,每个notification 都保持在原位。
是否将应用程序 badge number 设置为 0 或取消 local notifications 对此有任何影响。(我尝试评论这些部分,但没有解决)。
`func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {
Fabric.with([Crashlytics.self])
registerForPushNotifications(application)
application.registerForRemoteNotifications()
//Firebase push notification
FIRApp.configure()
// Add observer for InstanceID token refresh callback.
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.tokenRefreshNotification),
name: kFIRInstanceIDTokenRefreshNotification,
object: nil)
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
}`
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
guard let aps = userInfo["aps"] as? [String: AnyObject] else{
return
}
let state = UIApplication.sharedApplication().applicationState
if state == .Background || state == .Inactive{
//do some background work
}
}
任何帮助将不胜感激。
【问题讨论】:
-
你能展示你的代码吗?
-
我已经更新了我的问题
-
第二个通知有按钮,第一个没有按钮吗?
-
只需删除设置 applicationBadgeNumber 并尝试一次。
标签: ios swift push-notification