1
目前我使用的是所謂的「耳語」是應該與顯示應用程序內推送通知Whisper Link如何在應用程序打開時接收應用程序內推送通知?
在我的「didReceiveRemoteNotification」幫我把它設置如下庫:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if application.applicationState == .Active {
let navigationController = self.window!.rootViewController as! UINavigationController
if let aps = userInfo["aps"] as? NSDictionary {
if let alert = aps["alert"] as? NSDictionary {
if let title = alert["title"] as? NSString {
if let body = alert["body"] as? NSString {
let announcement = Announcement(title: title as! String, subtitle: body as! String, image: UIImage(named: "HolyGrailLogo-58"))
Shout(announcement, to: navigationController)
}
}
}
}
// Show and hide a message after delay
}
}
由於一些奇怪的原因,我沒有收到任何推送通知,不知道爲什麼。
應用程序請求用戶接受推送通知的權限嗎?您不應該檢查application.applicationState == .Active – picciano
我正在檢查application.applicationState == .Active以查看如果該應用程序是打開的。用戶應該已經接受推送通知 – SwiftyJD
您可以查看[此社區答案](https://support.layer.com/hc/en-us/articles/204632870-How-do-I-troubleshoot-issues-with-Push-Notifications-on-iOS-)可能的原因。 –