I am a newbie when it comes to Xcode and IOS development, although now seems like a good time to learn with the introduction of Swift. I've learned some basics and I wanted to know if there is a way to to register users and setup Apple remote push notifications in an APP that uses WKWebView to display a responsive website in the in App browser. I have that setup, and I've set up the notification registration in AppDelegate.swift so that it works generically for all users, signed in or not. I also have everything setup in terms of certificates with a local testing environment using a PHP script to send notifications, and I also have the nice little OS X app PushMeBaby for testing purposes.
I do have a few questions though. I might want to invoke the registration for notifications only after the user has signed in to the website displayed in the in App browser. The site is PHP/MySQL, and I need to set up some method by which to register then user and preferably return the device ID and the user ID to the remote server so that it can send out notifications to registered users.
Also wondering, just in general terms, how the remote server collects device ID's. Is this done when the user signs up for notifications by sending a response to the server, or is there another method by which to get an array of all device ID's that are registered (i.e. from the Apple service).
The basic code that I have in AppDelegate.swift is:
The basic features are working in the sandbox / development environment.
I do have a few questions though. I might want to invoke the registration for notifications only after the user has signed in to the website displayed in the in App browser. The site is PHP/MySQL, and I need to set up some method by which to register then user and preferably return the device ID and the user ID to the remote server so that it can send out notifications to registered users.
Also wondering, just in general terms, how the remote server collects device ID's. Is this done when the user signs up for notifications by sending a response to the server, or is there another method by which to get an array of all device ID's that are registered (i.e. from the Apple service).
The basic code that I have in AppDelegate.swift is:
Code:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Customized code, below is for Notification registration
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 characterSet: NSCharacterSet = NSCharacterSet( charactersInString: "<>" )
var deviceTokenString: String = ( deviceToken.description as NSString )
.stringByTrimmingCharactersInSet( characterSet )
.stringByReplacingOccurrencesOfString( " ", withString: "" ) as String
println( deviceTokenString )
}
func application( application: UIApplication!, didFailToRegisterForRemoteNotificationsWithError error: NSError! ) {
println( error.localizedDescription )
}
The basic features are working in the sandbox / development environment.