-
-
Save JuanPabloBoero/d96f7358a21ae71b3f11 to your computer and use it in GitHub Desktop.
Using Azure Notification Hubs in Swift
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
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
// Override point for customization after application launch. | |
let types: UIUserNotificationType = [.Badge, .Alert , .Sound] | |
var settings: UIUserNotificationSettings = UIUserNotificationSettings( forTypes: types, categories: nil ) | |
application.registerUserNotificationSettings( settings ) | |
application.registerForRemoteNotifications() | |
return true | |
} | |
func application( application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData! ) { | |
var hub : SBNotificationHub = SBNotificationHub(connectionString: "!!YOUR TOKEN HERE!!", notificationHubPath: "!!YOUR NOTIFICATION HUB PATH HERE!!") | |
hub.registerNativeWithDeviceToken(deviceToken, tags: nil) { (error) -> Void in | |
if (error != nil){ | |
println("Error registering for notifications: %@", error); | |
} | |
} | |
} | |
func application( application: UIApplication!, didFailToRegisterForRemoteNotificationsWithError error: NSError! ) { | |
println( error.localizedDescription ) | |
} | |
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { | |
println("User Info: %@", userInfo) | |
var alert = UIAlertController(title: "Notification", message: "Message", preferredStyle: UIAlertControllerStyle.Alert) | |
// alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil)) | |
self.window?.rootViewController?.presentViewController(alert, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment