顯然,現(xiàn)在ios10可以實(shí)現(xiàn):optional func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)這個(gè)答案基本上說(shuō)完成此任務(wù)所需的工具:當(dāng)您的應(yīng)用處于打開狀態(tài)且在前臺(tái)時(shí),顯示股票iOS通知橫幅嗎?我只是不太了解如何將所有內(nèi)容放在一起。我不知道這有多重要,但是我無(wú)法保留可選的func,而xcode希望我將其切換為私有。我正在嘗試顯示徽章,并且文檔提供了static var badge: UNNotificationPresentationOptions { get }有點(diǎn)丟在這里。然后,我假設(shè)是否要從獲取這些徽章中排除某個(gè)視圖控制器,并且我沒有使用導(dǎo)航控制器,那么我發(fā)現(xiàn)的這段代碼行得通嗎?:var window:UIWindow?if let viewControllers = window?.rootViewController?.childViewControllers {for viewController in viewControllers { if viewController.isKindOfClass(MyViewControllerClass) { print("Found it!!!") } }}
3 回答

躍然一笑
TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊
還可以設(shè)置在應(yīng)用程序處于前臺(tái)時(shí)顯示通知的關(guān)鍵:
content.setValue(true, forKey: "shouldAlwaysAlertWhileAppIsForeground")
在你的UNNotificationRequest。至于其他內(nèi)容,請(qǐng)參見Rajan Maheshwari的出色回答。
- 3 回答
- 0 關(guān)注
- 1159 瀏覽
添加回答
舉報(bào)
0/150
提交
取消