IOS Notification

First, let us know what push notification is?

Push notification is a pop message or alerts from an application to users and it can be for all users or specific users to announce something or notify the user about something based on his/her behalf.

History:

In June 2009: Apple launched Apple Push Notification Service (APNs).

May 2010: Google released its service (GCM).

May 2013: Google introduced “rich notifications”. Rich notifications can contain images, as well as action buttons. Action buttons let users take immediate action from a notification. For example, the user can play a song, open the app, or see more information.

In September 2014: Apple added interactive buttons. These buttons allow users to send a response right away to the app publisher. Shortly after, Apple extended push notifications to the Apple Watch.

Push Notification in iOS

In iOS, You can implement your web service with APNs but there is an easier way like firebase. 

 

Push Notification for iOS using firebase:

Firebase Cloud Messaging is the tool used to send push notifications to a single or a group of devices. Firebase Cloud Messaging: Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.

Steps to add push notifications using firebase:

First 

First: Go to https://firebase.google.com/docs/cloud-messaging, Then follow the steps mentioned below:

1- Go to the console, like the image below:

2- Add a project.

3- Choose a project name.

4- Follow the steps of creation.

Push notification Example photo

Push notification Example photo

Push notification Example photo

4- After the creation of the project choose the iOS icon to make google play services to your iOS project.

Push notification Example photo

5- Create your XCode project and copy the bundle identifier of the project.

Push notification Example photo

6- Add the bundle identifier.

7- Follow the steps and then download Google play service file.

8- Add it to your XCode project.

Push notification Example photo

Push notification Example photo

 

Second: iOS Side:

1- You must have a paid developer account.

2- Go to your project and create a pod file. And then add pods.

 


pod 'Firebase/Analytics
 
# For Analytics without IDFA collection capability, use this pod instead
# pod ‘Firebase/AnalyticsWithoutAdIdSupport’
 
# Add the pod for Firebase Cloud Messaging
pod 'Firebase/Messaging

3- After installation goes to your project, Then Import the Firebase module in your UIApplicationDelegate.

import Firebase, Then in the application:didFinishLaunchingWithOptions method adds these lines of code.


FirebaseApp.configure()
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] UNUserNotificationCenter.current().requestAuthorization( options: authOptions, completionHandler: {_, _ in }) } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil) application.registerUserNotificationSettings(settings) } application.registerForRemoteNotifications()

Now to get your unique firebase identifier token to use it like sending it to your backend through API to send you a specific notification.


func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//edit print(deviceToken , "deviiiiiice")
InstanceID.instanceID().instanceID(handler: { (result, error) in
if let error = error {
print("Error fetching remote instange ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")

}
})
}

Now go to your apple developer account and then:

1- Open certificates and IDs, and profiles.

 

 

 

 

 

 

 

 

2- Add a new certificate (development – production ).

3- Go to the services section and choose (apple push notification service SSL(sandbox) for development certificate ), And create a certificate.

 

4- After that do the same with (apple push notification service SSL(sandbox & production)for the production certificate).

5 – create the two certifications of both, Export both certifications and get a p12 file for both. 

6 – Go to your google account then firebase ios project.

7- Go to cloud messaging.

8- Add the p12 file to production and development.

9- Send your first message.

This is it :), I hope this article is useful to you.

 

Ibrahim Abdelhamid

IOS developer at Rabbit Technology

icon 01

Where We Are

El-Agamy, Marsa Matrwh Road/ Alexandria, Egypt.

feature icon 03

24/7 Tech Support

+20 120 549 9063

icon 03

E-mail Us

info@rabbittec.com

sales@rabbittec.com