Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 1fb66bf

Browse files
author
Jeff Linwood
committed
Port Chat Push iOS snippets to Conversations
Port Chat SDK reference to Conversations Port Chat Push iOS snippets to Conversations Style changes for code samples Fix spacing for Obj-C file Add newline to meta.json
1 parent 8310c62 commit 1fb66bf

File tree

24 files changed

+186
-0
lines changed

24 files changed

+186
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
func application(_ application: UIApplication, didFinishLaunchingWithOptions
2+
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"title": "Did Finish Launching",
3+
"type": "mobile"
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Do not forget to set up a delegate for UNUserNotificationCenter
2+
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
3+
didReceiveNotificationResponse:(UNNotificationResponse *)response
4+
withCompletionHandler:(void (^)(void))completionHandler {
5+
NSDictionary *userInfo = response.notification.request.content.userInfo;
6+
// If your application supports multiple types of push notifications,
7+
// you may wish to limit which ones you send to the TwilioConversationsClient here
8+
if (self.conversationsClient) {
9+
// If your reference to the Conversations client exists and is initialized,
10+
// send the notification to it
11+
[self.conversationsClient handleNotification:userInfo completion:^(TCHResult *result) {
12+
if (![result isSuccessful]) {
13+
// Handling of notification was not successful, retry?
14+
}
15+
}];
16+
} else {
17+
// Store the notification for later handling
18+
self.receivedNotification = userInfo;
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Do not forget to set up a delegate for UNUserNotificationCenter
2+
func userNotificationCenter(_ center: UNUserNotificationCenter,
3+
didReceive response: UNNotificationResponse,
4+
withCompletionHandler completionHandler: @escaping () -> Void) {
5+
let userInfo = response.notification.request.content.userInfo
6+
if let conversationsClient = conversationsClient, conversationsClient.user != nil {
7+
// If your reference to the Conversations client exists
8+
// and is initialized, send the notification to it
9+
conversationsClient.handleNotification(userInfo) { (result) in
10+
if !result.isSuccessful() {
11+
// Handling of notification was not successful, retry?
12+
}
13+
}
14+
} else {
15+
// Store the notification for later handling
16+
receivedNotification = userInfo
17+
}
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"title": "Did Receive Notification",
3+
"type": "mobile"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"title": "Register Notifications",
3+
"type": "mobile"
4+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if (self.updatedPushToken) {
2+
[self.conversationsClient registerWithNotificationToken:self.updatedPushToken
3+
completion:^(TCHResult *result) {
4+
if (![result isSuccessful]) {
5+
// try registration again or verify token
6+
}
7+
}];
8+
}
9+
10+
if (self.receivedNotification) {
11+
[self.conversationsClient handleNotification:self.receivedNotification
12+
completion:^(TCHResult *result) {
13+
if (![result isSuccessful]) {
14+
// Handling of notification was not successful, retry?
15+
}
16+
}];
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
if let updatedPushToken = updatedPushToken {
2+
conversationsClient.register(withNotificationToken: updatedPushToken) { (result) in
3+
if !result.isSuccessful() {
4+
// try registration again or verify token
5+
}
6+
}
7+
}
8+
9+
if let receivedNotification = receivedNotification {
10+
conversationsClient.handleNotification(receivedNotification) { (result) in
11+
if !result.isSuccessful() {
12+
// Handling of notification was not successful, retry?
13+
}
14+
}
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"title": "Store Registration",
3+
"type": "mobile"
4+
}

0 commit comments

Comments
 (0)