Here are the details of the error when app throw error to register the notification:
<EXPR>:3:1: error: expected member name or constructor call after type name
Error
^
<EXPR>:3:1: note: use '.self' to reference the type object
Error
^
.self
Here is the code which is running successfully in iOS 10.1
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error)
{
print("Failed to register Notification Error = ", Error)
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
{
print("Device Token = ", Data)
}
func registerForRemoteNotification()
{
if #available(iOS 10.0, *)
{
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge])
{ (granted, error) in
if error == nil
{
UIApplication.shared.registerForRemoteNotifications()
}
}
}
else
{
if #available(iOS 8.0, *)
{
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
}
else
{
UIApplication.shared.registerForRemoteNotifications(matching: [.badge, .sound, .alert])
}
}
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
if let dicAps = notification.request.content.userInfo["aps"] as? NSDictionary
{
AppUtilities.showAlertWithMessage(title: APP_TITLE as NSString, message: "\(dicAps.object(forKey: "msg")!)" as NSString)
}
completionHandler([.alert, .badge, .sound])
}
//Called to let your app know which action was selected by the user for a given notification.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
print("User Info = ",response.notification.request.content.userInfo)
}
I am trying to implement an app which will run on iOS 8 to 10.1., it works fine in iPhone 5s with iOS 10.1.1. but when I run the app in the simulator with iOS 8.1, it always throws an error which is described above, please correct me if I missed anything.
Thank you.