Push Notification
Push notification is a very important aspect in a chat application. Taptalk.io provides a convenient way to implement push notifications so you can easily manage them according to your needs. If you implement Taptalk.io with the UI implementation method, incoming notifications will be handled within our library and will be automatically shown to the user. If you prefer having full control over the push notifications, the core implementation method can be used.
Push notification for iOS client apps are sent using Apple Push Notification service (APNs). They are used for keeping your users informed with timely and relevant content, whether your client app is running in the background or inactive on a device. They can also perform the types of user interactions such as alert, sound, or badge, and include custom data your app needs to respond to the notifications.
Our iOS SDK enables you to build a client app that can receive push notifications. When a message is sent to TapTalk.io server through the SDK, the server communicates with APNs regarding the message and then APNs delivers a push notification for the message to an iOS device where your client app is installed.

Step 1: Generating your .p8 key file

Configuration with auth keys is recommended as they are the more current method for sending notifications to iOS.
A .p8 key file is required to send push notifications to your apps. There are some several ways to generate key for push notification, but Apple recommends to use APNs Auth Key (.p8 key file) to register for push notifications.
1. To generate a .p8 key file, go to Apple developer account page , then select Certificates, IDs & Profiles.
2. Next, select Keys tab.
3. Click "+" button or click Create a key button to add new key.
4. In the new key page, type in your key name and check the Apple Push Notification service (APNs) box, then click Continue.
5. Confirm your key information and click Register.
Then proceed to download the key file by clicking Download.
Please remember the Key ID provided in the information above or you can see the Key ID from the downloaded file. The Auth Key filename will look like this : AuthKey_ABC12DE34.p8, the ABC12DE34 is the Key ID for this key, we will need this Key ID later.

Step 2: Using .p8 key file in TapTalk.io dashboard to send push notification

1. Go to TapTalk.io Dashboard page, and login to your dashboard.Select Tab Development -> Push Certificates 2. Select Tab Development -> Push Certificates
3. Next, select Add APNs Authentication Key
4. Upload .p8 Authentication Key, add APN Key ID, add Team ID, and select to show unread count option
You can find your Team ID in the Apple Member Center under the membership tab.
Show Unread Count
You can choose either to show unread count by chat room or not show unread count

Step 3: Implement push notification in your app

1. The first step is to implement UIApplicationDelegate & TapTalkApplicationDelegate in your AppDelegate class.
Objective-C
AppDelegate.m
1
//AppDelegate.m
2
3
@interface AppDelegate () <TapTalkDelegate, UNUserNotificationCenterDelegate>
4
5
@end
6
7
//Implement didRegisterForRemoteNotificationsWithDeviceToken: method to tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
8
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
9
10
//Call TapTalk didRegisterForRemoteNotificationsWithDeviceToken: method
11
[[TapTalk sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
12
}
13
14
//Implement didReceiveRemoteNotification: method to tells the app that a remote notification arrived that indicates there is data to be fetched.
15
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
16
17
//Call TapTalk didReceiveRemoteNotification: method
18
[[TapTalk sharedInstance] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
19
}
Copied!
2. Request authorization to Apple Push Notification Service (APNs) by using this method in your appDelegate class with application:didFinishLaunchingWithOptions: method.
Objective-C
AppDelegate.m
1
//AppDelegate.m
2
3
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
4
5
//Register for notification in didFinishLaunchingWithOptions: method
6
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
7
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge
8
9
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions completionHandler:^(BOOL granted, NSError * _Nullable error) {
10
}];
11
}
Copied!
3. Implement UNUserNotificationCenterDelegate to handle notification in your appDelegate class.
Objective-C
AppDelegate.m
1
//AppDelegate.m
2
3
//Add UNUserNotificationCenterDelegate
4
@interface AppDelegate () <UNUserNotificationCenterDelegate>
5
6
@end
7
8
@implementation AppDelegate
9
#pragma mark UNUserNotificationCenter
10
//Implement UNUserNotificationCenter delegate
11
//This method let the app knows when a notification is delivered to a foreground.
12
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
13
14
//Add TapTalk.io method to handle willPresentNotification method
15
[[TapTalk sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
16
}
17
18
//This method let your app know which action was selected by the user for a given notification.
19
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
20
21
//Add TapTalk.io method to handle didReceiveNotificationResponse method
22
[[TapTalk sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
23
}
24
25
@end
Copied!
4. Implement TapTalkDelegate in appDelegate class.
Objective-C
AppDelegate.m
1
//AppDelegate.m
2
3
//Add TapTalkDelegate and previous UNUserNotificationCenterDelegate
4
@interface AppDelegate () <UNUserNotificationCenterDelegate, TapTalkDelegate>
5
6
@end
7
8
@implementation AppDelegate
9
#pragma mark - Delegate
10
#pragma mark TapTalk
11
12
//Implement TapTalk Delegate and add code below
13
- (void)tapTalkDidRequestRemoteNotification {
14
//Register to receive remote notifications via Apple Push Notification service
15
[[UIApplication sharedApplication] registerForRemoteNotifications];
16
}
17
18
@end
Copied!

Add In-App Notification

TapTalk.io provides in-app notification handling. This following code enables you to activate and show in-app notification.
Objective-C
AppDelegate.m
1
// AppDelegate.m
2
3
//import TapUI
4
#import <TapTalk/TapUI.h>
5
6
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
7
8
//To activate in-app push notification with your current window
9
[[TapUI sharedInstance] activateTapTalkInAppNotification:YES];
10
11
}
Copied!
Note: You will not receive any in-app notification if you don't implement this method.
Last modified 2mo ago