iOS developers India are excited and would like to share this tutorial with the 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 enabled 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 a new certificate. After that select “Apple Push Notification Service SSL (Sandbox)” in the development section and press “Continue”. If you want to, create production certification than select type on production section. These things show in below screenshot.
Next press continues to upload CSR file. 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. The last field remains blank as shown in below screenshot.
Next, go to safari and upload the CSR file that we created. After uploading press “continue”.
The last step is to download the certificate and install to a keychain. Please check below screenshot.
Now move to the project and add a new framework “UserNotifications”. This framework 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 the project into the device. If everything is correct, your app should run properly, and you will get the device token in the console. Copy the device token and open any APN server app for sending push notification. Here we have used the “APN Tester Free” app for sending a notification. Paste device token to Device Token field and upload certificate to Certificate field. Press the 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.