0

我试图让我的用户通过 OneSignal 接收通知,但我使用的是 Swift 2.3 并且有一台无法升级到 XCode 8 的旧版 Macbook。这可能吗?如何?这是建议的 OneSignal Swift 代码...

 OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)

        OneSignal.initWithLaunchOptions(launchOptions, appId: "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", 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 actionSelected = result?.action.actionID {
                    fullMessage =  fullMessage! + "\nPressed ButtonId:\(actionSelected)"
                }

                print(fullMessage)

            }, settings: [kOSSettingsKeyAutoPrompt : true,
                          kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.notification.rawValue])

        OneSignal.idsAvailable({ (userId, pushToken) in
            print("UserId:%@", userId);
            if (pushToken != nil) {
                NSLog("Sending Test Noification to this device now");
                OneSignal.postNotification(["contents": ["en": "Test Message"], "include_player_ids": [userId]]);
            }
        });


        // iOS 10 ONLY - Add category for the OSContentExtension
        // Make sure to add UserNotifications framework in the Linked Frameworks & Libraries.
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().getNotificationCategories { (categories) in
                let myAction = UNNotificationAction(identifier: "action0", 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)
            }
        }

        return true
    }
4

0 回答 0