Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
4 changes: 4 additions & 0 deletions conversations/push-ios/didfinishlaunching/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Did Finish Launching",
"type": "mobile"
}
20 changes: 20 additions & 0 deletions conversations/push-ios/didreceiveremote/didreceiveremote.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Do not forget to set up a delegate for UNUserNotificationCenter
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
NSDictionary *userInfo = response.notification.request.content.userInfo;
// If your application supports multiple types of push notifications,
// you may wish to limit which ones you send to the TwilioConversationsClient here
if (self.conversationsClient) {
// If your reference to the Conversations client exists and is initialized,
// send the notification to it
[self.conversationsClient handleNotification:userInfo completion:^(TCHResult *result) {
if (![result isSuccessful]) {
// Handling of notification was not successful, retry?
}
}];
} else {
// Store the notification for later handling
self.receivedNotification = userInfo;
}
}
18 changes: 18 additions & 0 deletions conversations/push-ios/didreceiveremote/didreceiveremote.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Do not forget to set up a delegate for UNUserNotificationCenter
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
if let conversationsClient = conversationsClient, conversationsClient.user != nil {
// If your reference to the Conversations client exists
// and is initialized, send the notification to it
conversationsClient.handleNotification(userInfo) { (result) in
if !result.isSuccessful() {
// Handling of notification was not successful, retry?
}
}
} else {
// Store the notification for later handling
receivedNotification = userInfo
}
}
4 changes: 4 additions & 0 deletions conversations/push-ios/didreceiveremote/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Did Receive Notification",
"type": "mobile"
}
4 changes: 4 additions & 0 deletions conversations/push-ios/registernotifications/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Register Notifications",
"type": "mobile"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if (self.updatedPushToken) {
[self.conversationsClient registerWithNotificationToken:self.updatedPushToken
completion:^(TCHResult *result) {
if (![result isSuccessful]) {
// try registration again or verify token
}
}];
}

if (self.receivedNotification) {
[self.conversationsClient handleNotification:self.receivedNotification
completion:^(TCHResult *result) {
if (![result isSuccessful]) {
// Handling of notification was not successful, retry?
}
}];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if let updatedPushToken = updatedPushToken {
conversationsClient.register(withNotificationToken: updatedPushToken) { (result) in
if !result.isSuccessful() {
// try registration again or verify token
}
}
}

if let receivedNotification = receivedNotification {
conversationsClient.handleNotification(receivedNotification) { (result) in
if !result.isSuccessful() {
// Handling of notification was not successful, retry?
}
}
}
4 changes: 4 additions & 0 deletions conversations/push-ios/remotenotifications/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Store Registration",
"type": "mobile"
}
17 changes: 17 additions & 0 deletions conversations/push-ios/remotenotifications/remotenotifications.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
if (self.conversationsClient && self.conversationsClient.user) {
[self.TwilioConversationsClient registerWithNotificationToken:deviceToken
completion:^(TCHResult *result) {
if (![result isSuccessful]) {
// try registration again or verify token
}
}];
} else {
self.updatedPushToken = deviceToken;
}
}

- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
NSLog(@"Failed to get token, error: %@", error);
self.updatedPushToken = nil;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("Received device token")
if let conversationsClient = conversationsClient, conversationsClient.user != nil {
conversationsClient.register(withNotificationToken: deviceToken) { (result) in
if !result.isSuccessful() {
// try registration again or verify token
}
}
} else {
updatedPushToken = deviceToken
}
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to get token, error: %@", error)
updatedPushToken = nil
}
4 changes: 4 additions & 0 deletions conversations/push-ios/systemversion/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Notification Types",
"type": "mobile"
}
6 changes: 6 additions & 0 deletions conversations/push-ios/systemversion/systemversion.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
UNUserNotificationCenter *currentNotificationCenter = [UNUserNotificationCenter currentNotificationCenter];
[currentCenter requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionAlert | UNAuthorizationOptionSound
completionHandler:^(BOOL granted, NSError *error) {
// Add here your handling of granted or not granted permissions
}];
currentNotificationCenter.delegate = self;
13 changes: 13 additions & 0 deletions conversations/push-ios/systemversion/systemversion.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
print("User allowed notifications:", granted)
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
if error {
print(error.localizedDescription)
}
}
}
4 changes: 4 additions & 0 deletions conversations/push-ios/updatebadgecount/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "Update Badge Count",
"type": "mobile"
}
3 changes: 3 additions & 0 deletions conversations/push-ios/updatebadgecount/updatebadgecount.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- (void)conversationsClient:(TwilioConversationsClient *)client notificationUpdatedBadgeCount:(NSUInteger)badgeCount {
[UIApplication.currentApplication setApplicationIconBadgeNumber:badgeCount];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func conversationsClient(_ client: TwilioConversationsClient, notificationUpdatedBadgeCount badgeCount: UInt) {
UIApplication.shared.applicationIconBadgeNumber = Int(badgeCount)
}
4 changes: 4 additions & 0 deletions conversations/push-ios/usernotificationsettings/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"title": "User Notification Setttings",
"type": "mobile"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Add this to the didFinishLaunchingWithOptions function or a similar place
// once you get granted permissions
UNUserNotificationCenter *currentNotificationCenter = [UNUserNotificationCenter currentNotificationCenter];
[currentNotificationCenter getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings) {
if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
[UIApplication.sharedApplication registerForRemoteNotifications];
}
}];
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let center = UNUserNotificationCenter.current()
center.getNotificationSettings { (settings) in
if settings.authorizationStatus == .authorized {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
4 changes: 4 additions & 0 deletions conversations/push-ios/variables/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "mobile",
"title": "Conversations Push State Variables"
}
3 changes: 3 additions & 0 deletions conversations/push-ios/variables/variables.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@property (nonatomic, strong) NSData *updatedPushToken;
@property (nonatomic, strong) NSDictionary *receivedNotification;
@property (nonatomic, strong) TwilioConversationsClient *conversationsClient;
3 changes: 3 additions & 0 deletions conversations/push-ios/variables/variables.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var updatedPushToken: Data?
var receivedNotification: [AnyHashable: Any]?
var conversationsClientClient: TwilioConversationsClient?