Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • UINotification in iOS10, Swift 3.0

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.23k
    Comment on it

    To implement Notification in iOS 10, follow below steps.

    Go to Project -> Target -> capabilities -> push notifications
    enable push notification.

    Now in Your AppDelegate Class do following steps -

    1. Import UserNotifications.
    2. Assign “UNUserNotificationCenterDelegate“ Delegate to this class.

    import UserNotifications
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate

    3. In didFinishLaunchingWithOptions method implement “UNUserNotificationCenter” delegate and “UIUserNotificationSettings”.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            
            // Override point for customization after application launch.
            let center = UNUserNotificationCenter.current()
            center.delegate = self
            center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
                // Enable or disable features based on authorization.
                if granted == true
                {
                    UIApplication.shared.registerForRemoteNotifications()
                }}
            return true
        }
    

    4.Now implement delegate methods of “UNUserNotificationCenter”

    // The method will be called when application is in the foreground.
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            //You can set notification presented as a sound, badge, alert and/or in the notification list.
            completionHandler(UNNotificationPresentationOptions.alert)
        }
    
    // The method will be called when the user tap on the notification by opening the application, dismissing the notification or choosing a UNNotificationAction.
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Swift.Void){
            // Handle response accordingly. 
    
        }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: