iOS developers India are excited and would like to share this tutorial with entire development community. They would like to make people learn how to implement push notification in iOS 10 using Swift 3.0 language. Read the post and find how professionals do it at their work station.
One liner: In this tutorial we will learn about how to implement push notification in iOS 10 devices with swift 3.0 language.
1. Xcode 8+
2. Swift 3.0
3. iOS 8+
Start by creating one SingleViewApplication with product name PushNotificationDemo. In language select swift and devices field select universal.
The first step in setting up push notification is enable push notification. For that go to the target and select Capabilities tab. In Push Notifications toggle value set ON. Please check below screenshot.
Next step is generating an authentication certificate that will allow authenticating backend server with APNs when it wants to send your device a push notification. For new certificate go to your apple account certificate section and press “+” for new certificate. After that select “Apple Push Notification Service SSL (Sandbox)” in development section and press “Continue”. If you want to create production certification than select type on production section. These things are show in below screenshot.
Next select your App ID and press continues. Please check below screenshot.
Next press continue for upload CSR file. Please check below screenshot.
For creating CSR file open keychain and select “Request a Certificate From a Certificate Authority…” Please check below screenshot.
In the certificate Assistant enter user email address and name. Last field remain blank as show in below screenshot.
Next go to safari and upload CSR file that we created. After uploading press “continue”.
Last step is download certificate and install to keychain. Please check below screenshot.
Now move to project and add new framework “UserNotifications”. This framework was introduced from iOS 10. Open Appdelegate.swift and import “UserNotifications” frameworks. To request device token for current device add below code to didFinishLaunchingWithOptions() method.
Add two methods to Appdelegate.swift class. The first method didRegisterForRemoteNotificationsWithDeviceToken called when APNs has assigned the device token. Second method didFailToRegisterRemoteNotificationsWithError called if APNs failed to register the device. Please check below screenshot.
Add didReceiveRemoteNotification method for receiving push notification. Please check below screenshot.
Now build and run project into device. If everything is correct, your app should run properly and you will get device token in console. Copy the device token and open any APN server app for sending push notification. Here we have use “APN Tester Free” app for sending notification. Paste device token to Device Token field and upload certificate to Certificate field. Press push button to send the push notification with Payload to the Device. Please check below screenshot for more info.
Now check your device you should get below output.
iOS developers India have just shared this tutorial with global development community people. They have shared clear points that tell the best way to implement push notification in iOS 10 using Swift 3.0 language. If you want to know more about push notifications or Swift language, make comments.