Skip to content

Instantly share code, notes, and snippets.

@vikdenic
Created September 25, 2017 20:58
Show Gist options
  • Save vikdenic/8a81359760bbd8368d36f46b40ee1944 to your computer and use it in GitHub Desktop.
Save vikdenic/8a81359760bbd8368d36f46b40ee1944 to your computer and use it in GitHub Desktop.
one signal setup
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