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
}