Skip to content

Instantly share code, notes, and snippets.

@suparngp
Last active October 19, 2015 19:47
Show Gist options
  • Save suparngp/1109c80e2e90a2f48432 to your computer and use it in GitHub Desktop.
Save suparngp/1109c80e2e90a2f48432 to your computer and use it in GitHub Desktop.
import PushKit
import AdSupport
import Foundation
class AppDelegate: UIResponder, UIApplicationDelegate {
var voipRegistry:PKPushRegistry!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//register for notifications
registerVoipNotifications()
return true
}
//PushKit functions
func registerVoipNotifications() {
let types:UIUserNotificationType = [UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let notificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
}
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
voipRegistry = PKPushRegistry(queue: dispatch_get_main_queue())
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = Set([PKPushTypeVoIP])
Logger.debug("VOIP Push registered")
}
}
extension AppDelegate: PKPushRegistryDelegate{
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
let pushToken: String! = credentials.token.description
Logger.debug("\n\n##### PushKit credential: %@\n\n", pushToken)
}
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
let data = payload.dictionaryPayload
Logger.debug("\n\n##### Received PushKit Data: %@ \n\n", data)
}
}
@suparngp
Copy link
Author

Logger.debug just wraps the NSLog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment