0

I'm trying to let me users receive notifications over OneSignal, but I'm using Swift 2.3 and have an older Macbook that cannot upgrade to XCode 8. Is this possible? And how? Here is the suggested OneSignal Swift Code...

 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
    }
Charles Jr
  • 8,333
  • 15
  • 53
  • 74
  • I don't understand why you are asking how to not use the user notification framework, but then its in the code. Why is it in the code if you don't want to use it? The old way of using notifications is deprecated, but that doesn't mean it won't still work. – Gruntcakes Mar 02 '17 at 16:13
  • @halfmanhalfpie I was asking because that specific framework is not part of my version of XCode and I want to ensure that notifications will be received properly for iOS 10 – Charles Jr Mar 02 '17 at 16:48
  • 1
    The old way of using notifications should work with iOS 10, you will just receive some deprecation build warnings. – Gruntcakes Mar 02 '17 at 16:51

0 Answers0