{"id":21962293,"url":"https://github.com/ashishkakkad8/notifications10swift","last_synced_at":"2025-08-01T16:42:42.784Z","repository":{"id":85487690,"uuid":"69319581","full_name":"ashishkakkad8/Notifications10Swift","owner":"ashishkakkad8","description":"Push Notifications in iOS10 - Swift 3","archived":false,"fork":false,"pushed_at":"2020-10-01T04:03:37.000Z","size":21,"stargazers_count":15,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T03:41:11.239Z","etag":null,"topics":["ios","ios10","notifications","notifications-entitlements","push-notifications","pushnotifications","swift","usernotifications"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashishkakkad8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-27T04:35:00.000Z","updated_at":"2019-07-01T11:03:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"ed0f10d7-deb1-47be-8031-2b12fd29967a","html_url":"https://github.com/ashishkakkad8/Notifications10Swift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashishkakkad8%2FNotifications10Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashishkakkad8%2FNotifications10Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashishkakkad8%2FNotifications10Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashishkakkad8%2FNotifications10Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashishkakkad8","download_url":"https://codeload.github.com/ashishkakkad8/Notifications10Swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250515326,"owners_count":21443371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","ios10","notifications","notifications-entitlements","push-notifications","pushnotifications","swift","usernotifications"],"created_at":"2024-11-29T10:37:19.396Z","updated_at":"2025-04-23T21:21:57.039Z","avatar_url":"https://github.com/ashishkakkad8.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Push Notifications in iOS 10 [Swift 3]\n\n\u003cp align=\"justify\"\u003eThe new framework called \"UserNotifications\"\tis introduced with iOS 10 SDK. The \u003ca href=\"https://developer.apple.com/reference/usernotifications\" target=\"_blank\"\u003eUserNotifications framework\u003c/a\u003e (UserNotifications.framework) supports the delivery and handling of local and remote notifications.\n\nSo, Let see what we have to change to get the push notifications in iOS 10.\n\u003c/p\u003e\n\n##Steps for implement code to handle push notifications in iOS 10\n\n###Import UserNotifications.framework in your AppDelegate file\n\n```swift\nimport UserNotifications\n```\nAlso add UNUserNotificationCenterDelegate.\n\n```swift\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {\n}\n```\n###Register for push notification\n\n\u003cp align=\"justify\"\u003eBefore registration check the version of iOS and then based on versions do the code. For iOS 7 code was different, fro iOS 8 \u0026 9 code was different and again for iOS 10 code is different.\u003c/p\u003e\n\n\u003cp align=\"justify\"\u003e\u003cem\u003eAs per my opinion you have to set the deployment target to iOS 8 or iOS 9 and later. For this you can check the \u003ca href=\"https://developer.apple.com/support/app-store/\" target=\"_blank\"\u003eadoption ratio of iOS\u003c/a\u003e in the devices.\u003c/em\u003e\u003c/p\u003e\n\n\u003cstrong\u003eAdd code in your did finish launching\u003c/strong\u003e\n\n```swift\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n    // Override point for customization after application launch.\n    registerForRemoteNotification()        \n    return true\n}\n \nfunc registerForRemoteNotification() {\n    if #available(iOS 10.0, *) {\n        let center  = UNUserNotificationCenter.current()\n        center.delegate = self\n        center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in\n            if error == nil{\n                UIApplication.shared.registerForRemoteNotifications()\n            }\n        }\n    }\n    else {\n        UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))\n        UIApplication.shared.registerForRemoteNotifications()\n    }\n}\n```\n\n###Handling delegate methods for UserNotifications\n\n\u003cp align=\"justify\"\u003e\u003cstrong\u003e\u003cem\u003eYou will be surprise that notification displayed when application in foreground too in iOS 10. As we know that in old versions we display alert or something else which will be look like notification comes in foreground.\u003c/em\u003e\u003c/strong\u003e\u003c/p\u003e\n\nThere are two delegate methods need to be handled :\n\n```swift\n//Called when a notification is delivered to a foreground app.\n@available(iOS 10.0, *)\nfunc userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -\u003e Void) {\n    print(\"User Info = \",notification.request.content.userInfo)\n    completionHandler([.alert, .badge, .sound])\n}\n \n//Called to let your app know which action was selected by the user for a given notification.    \n@available(iOS 10.0, *)\nfunc userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -\u003e Void) {\n    print(\"User Info = \",response.notification.request.content.userInfo)\n    completionHandler()\n}\n```\n\n###Add Push Notifications Entitlements\n\n\u003cp align=\"justify\"\u003eGo to your project target's \u003cstrong\u003eCapabilities\u003c/strong\u003e tab and add Push Notifications Entitlements.\u003c/p\u003e\n\n\u003cimg src=\"http://ashishkakkad.com/wp-content/uploads/2016/09/Push-Notifications-Entitlements.png\" alt=\"Push Notifications Entitlements\" /\u003e\n\n\u003cp align=\"justify\"\u003eIf it's available in your certificates then it will enable directly else configure your profile with the certificates and you can enable this capability by that.\u003c/p\u003e\n\n\u003cb\u003eBlogpost on my website : \u003ca href=\"http://ashishkakkad.com/2016/09/push-notifications-in-ios-10-swift/\" target=\"_blank\"\u003ePush Notifications in iOS 10 [Swift]\u003c/a\u003e\u003c/b\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashishkakkad8%2Fnotifications10swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashishkakkad8%2Fnotifications10swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashishkakkad8%2Fnotifications10swift/lists"}