Skip to content

Instantly share code, notes, and snippets.

@JuanPabloBoero
Forked from fotiDim/gist:d18dd0f0ddb91ee3babc
Last active December 2, 2015 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JuanPabloBoero/d96f7358a21ae71b3f11 to your computer and use it in GitHub Desktop.
Save JuanPabloBoero/d96f7358a21ae71b3f11 to your computer and use it in GitHub Desktop.
Using Azure Notification Hubs in Swift
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