简体   繁体   English

Swift onesignal可以让我的应用程序支持ios 9和ios 10通知

[英]Swift onesignal can I allow my app to support both ios 9 and ios 10 notifications

I wonder if I can allow my app to support both ios 9 and ios 10 notifications? 我想知道我是否可以允许我的应用程序同时支持ios 9和ios 10通知?

I just integrated onesignal a notification service into my app and looked into the ios10 part which support videos/gifs etc. 我只是将一个通知服务整合到我的应用程序中,并查看支持视频/ GIF等的ios10部分。

So if I want to allow notifications into my app can I only support ios9 or can I support ios 10 as well, I mean if the notification falls back into ios 9 style if device runs that. 因此,如果我想允许通知进入我的应用程序,我可以只支持ios9,或者我也可以支持ios 10,我的意思是如果设备运行时通知会回退到ios 9样式。

Right now I have this: 现在我有这个:

OneSignal.initWithLaunchOptions(launchOptions, appId: "myId", handleNotificationReceived: { (notification) in
            print("Received Notification - \(notification?.payload.notificationID)")
        }, handleNotificationAction: { (result) in

            // This block gets called when the user reacts to a notification received
            let payload = result?.notification.payload
            var fullMessage = payload?.title

            //Try to fetch the action selected
            if let additionalData = payload?.additionalData, let actionSelected = additionalData["actionSelected"] as? String {
                fullMessage =  fullMessage! + "\nPressed ButtonId:\(actionSelected)"
            }
            print(fullMessage)
        }, settings: [kOSSettingsKeyAutoPrompt : true, kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.notification.rawValue])

if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().getNotificationCategories { (categories) in
                let myAction = UNNotificationAction(identifier: "actionSelected", title: "Hit Me!", options: .foreground)
                let myCategory = UNNotificationCategory(identifier: "myOSContentCategory", actions: [myAction], intentIdentifiers: [], options: .customDismissAction)
                let mySet = NSSet(array: [myCategory]).addingObjects(from: categories) as! Set<UNNotificationCategory>
                UNUserNotificationCenter.current().setNotificationCategories(mySet)
            }
        }

如果您在OneSignal的仪表板或REST API上设置iOS 10媒体附件,它仍将被发送到没有附件的iOS 9和旧设备。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM