Last active
April 16, 2018 13:14
-
-
Save fotiDim/d18dd0f0ddb91ee3babc 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. | |
var types: UIUserNotificationType = UIUserNotificationType.Badge | | |
UIUserNotificationType.Alert | | |
UIUserNotificationType.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
In Swift 2.1 , the line:
changed to this: