Created
September 25, 2017 20:58
-
-
Save vikdenic/8a81359760bbd8368d36f46b40ee1944 to your computer and use it in GitHub Desktop.
one signal setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let notificationReceivedBlock: OSHandleNotificationReceivedBlock = { notification in | |
if let notification = notification, let payload = notification.payload, let notifId = payload.notificationID { | |
print("📡Received Notification: \(notifId)") | |
} | |
} | |
let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in | |
print("☝️reacted to notif") | |
// This block gets called when the user reacts to a notification received | |
if let payload: OSNotificationPayload = result!.notification.payload { | |
self.handleRemoteNotification(payload: payload) | |
} | |
} | |
let onesignalInitSettings = [kOSSettingsKeyAutoPrompt: false, | |
kOSSettingsKeyInAppLaunchURL: true] | |
OneSignal.initWithLaunchOptions(launchOptions, | |
appId: SPKConfig.sharedInstance.oneSignalAPIKey(), | |
handleNotificationReceived: notificationReceivedBlock, | |
handleNotificationAction: notificationOpenedBlock, | |
settings: onesignalInitSettings) | |
let status: OSPermissionSubscriptionState = OneSignal.getPermissionSubscriptionState() | |
if let osUserId = status.subscriptionStatus.userId { | |
logItem("OneSignal userid: \(osUserId)") | |
} | |
else { | |
logItem("OneSignal userid: Not Defined") | |
} | |
OneSignal.add(self as OSSubscriptionObserver) | |
OneSignal.inFocusDisplayType = OSNotificationDisplayType.notification; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment