I\'ve built an application for iPhone using Swift and Xcode 6, and the Parse framework to handle services.
While following the Parse tutorials on how to set up push noti
This is for Swift 2. I have placed promptUserToRegisterPushNotifications() in MainViewController.swift, but I have left didRegisterForRemoteNotificationsWithDeviceToken in AppDelegate because it didn't work when I place it on the same MainViewController.swift.
// In 'MainViewController.swift' file
func promptUserToRegisterPushNotifications() {
// Register for Push Notifications
let application: UIApplication = UIApplication.sharedApplication()
if application.respondsToSelector(#selector(UIApplication.registerUserNotificationSettings(_:))) {
print("registerUserNotificationSettings.RegisterForRemoteNotificatios")
let notificationSettings = UIUserNotificationSettings(
forTypes: [.Badge, .Sound, .Alert], categories: nil)
application.registerUserNotificationSettings(notificationSettings) // Register for Remote Push Notifications
application.registerForRemoteNotifications()
}
}
// In AppDelegate
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let tokenChars = UnsafePointer(deviceToken.bytes)
var tokenString = ""
for i in 0..