From eb5a0c17d3521e30e510cf4c1f3a287660c9924e Mon Sep 17 00:00:00 2001 From: ashfaq14060 <129155175+ashfaq14060@users.noreply.github.com> Date: Sat, 27 Jan 2024 00:39:17 +0500 Subject: [PATCH 1/4] Update RNCallKeep.m --- ios/RNCallKeep/RNCallKeep.m | 67 +++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 9569e359..ebb9f5aa 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -1082,8 +1082,71 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) #ifdef DEBUG NSLog(@"[RNCallKeep][CXProviderDelegate][provider:performEndCallAction]"); #endif - [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; - [action fulfill]; + + if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) { + NSLog(@"Rejecting call in background, starting the background task to complete the rejection."); + + // Start a background task to ensure that the rejection process completes + UIBackgroundTaskIdentifier backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ + // The expiration handler is called if the background task is about to be terminated + // You can use this block to clean up or perform additional tasks if needed + // ... + + // End the background task + [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + }]; + NSString *callUUID = [action.callUUID.UUIDString lowercaseString]; + + // Perform any background tasks needed (e.g., network requests, cleanup) + NSString *urlString = [NSString stringWithFormat:@"https://tbudux3y2l.execute-api.us-east-1.amazonaws.com/uat/update-phone-call-session/%@", callUUID]; + + + // Create the URL + NSURL *url = [NSURL URLWithString:urlString]; + + // Create a mutable request + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + + // Set the HTTP method to POST + [request setHTTPMethod:@"POST"]; + + // Set the content type header + [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; + + // Create the request body as a dictionary + NSDictionary *requestBody = @{@"status": @"DECLINED"}; + + // Convert the dictionary to JSON data + NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestBody options:0 error:nil]; + + // Set the request body + [request setHTTPBody:requestData]; + + // Log the request URL (instead of the raw data) + NSLog(@"Request URL: %@", urlString); + + // Create a URLSession task + NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (error) { + NSLog(@"Error sending POST request: %@", error.localizedDescription); + } else { + // Handle the response + NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + NSLog(@"POST request response: %@", responseString); + } + + // End the background task + [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + }]; + + // Start the task + [task resume]; + [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; + [action fulfill]; + }else{ + [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; + [action fulfill]; + } } -(void)provider:(CXProvider *)provider performSetHeldCallAction:(CXSetHeldCallAction *)action From e75f4d19a713a7f1898ce02faf3cbd912b118c6c Mon Sep 17 00:00:00 2001 From: ashfaq14060 <129155175+ashfaq14060@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:51:02 +0500 Subject: [PATCH 2/4] Update RNCallKeep.m --- ios/RNCallKeep/RNCallKeep.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index ebb9f5aa..33aee8c4 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -1137,6 +1137,7 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) // End the background task [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + [self clearInitialEvents]; }]; // Start the task @@ -1146,6 +1147,7 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) }else{ [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; [action fulfill]; + [self clearInitialEvents]; } } From 8ce177e2e4df37684f015c1cea864a07bbb776a6 Mon Sep 17 00:00:00 2001 From: ashfaq14060 <129155175+ashfaq14060@users.noreply.github.com> Date: Mon, 19 Aug 2024 01:30:01 +0500 Subject: [PATCH 3/4] Update RNCallKeep.m --- ios/RNCallKeep/RNCallKeep.m | 53 +++++++++++++++---------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 33aee8c4..4511680f 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -1076,7 +1076,7 @@ - (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAct [action fulfill]; } -// Ending incoming call +// End incoming call - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action { #ifdef DEBUG @@ -1086,65 +1086,54 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) { NSLog(@"Rejecting call in background, starting the background task to complete the rejection."); - // Start a background task to ensure that the rejection process completes - UIBackgroundTaskIdentifier backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ - // The expiration handler is called if the background task is about to be terminated - // You can use this block to clean up or perform additional tasks if needed - // ... - - // End the background task + __block UIBackgroundTaskIdentifier backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{ [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + backgroundTask = UIBackgroundTaskInvalid; }]; - NSString *callUUID = [action.callUUID.UUIDString lowercaseString]; - // Perform any background tasks needed (e.g., network requests, cleanup) - NSString *urlString = [NSString stringWithFormat:@"https://tbudux3y2l.execute-api.us-east-1.amazonaws.com/uat/update-phone-call-session/%@", callUUID]; + MMKV *mmkv = [MMKV defaultMMKV]; + NSString *region = [mmkv getStringForKey:@"region"]; + NSString *callUUID = [action.callUUID.UUIDString lowercaseString]; + NSString *urlString; - // Create the URL - NSURL *url = [NSURL URLWithString:urlString]; + if ([region isEqualToString:@"US"]) { + urlString = [NSString stringWithFormat:@"https://k9t6db0ug0.execute-api.us-east-1.amazonaws.com/staging/update-phone-call-session/%@", callUUID]; + NSLog(@"Region value: %@", region); + } else { + urlString = [NSString stringWithFormat:@"https://dgmu1e4drb.execute-api.eu-central-1.amazonaws.com/staging/update-phone-call-session/%@", callUUID]; + NSLog(@"Using non-US region or no region value found in MMKV"); + } - // Create a mutable request + NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; - - // Set the HTTP method to POST [request setHTTPMethod:@"POST"]; - - // Set the content type header [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; - // Create the request body as a dictionary NSDictionary *requestBody = @{@"status": @"DECLINED"}; - - // Convert the dictionary to JSON data NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestBody options:0 error:nil]; - - // Set the request body [request setHTTPBody:requestData]; - // Log the request URL (instead of the raw data) NSLog(@"Request URL: %@", urlString); - // Create a URLSession task NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"Error sending POST request: %@", error.localizedDescription); } else { - // Handle the response NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"POST request response: %@", responseString); } - // End the background task - [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": callUUID }]; + [action fulfill]; [self clearInitialEvents]; + + [[UIApplication sharedApplication] endBackgroundTask:backgroundTask]; + backgroundTask = UIBackgroundTaskInvalid; }]; - // Start the task [task resume]; - [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; - [action fulfill]; - }else{ + } else { [self sendEventWithNameWrapper:RNCallKeepPerformEndCallAction body:@{ @"callUUID": [action.callUUID.UUIDString lowercaseString] }]; [action fulfill]; [self clearInitialEvents]; From b6326b39d79fb31b19668382f55c8d5a196e3b24 Mon Sep 17 00:00:00 2001 From: ashfaq14060 <129155175+ashfaq14060@users.noreply.github.com> Date: Mon, 19 Aug 2024 02:12:21 +0500 Subject: [PATCH 4/4] Update RNCallKeep.m --- ios/RNCallKeep/RNCallKeep.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index 4511680f..bc05fc74 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -16,6 +16,8 @@ #import #import +#import + #ifdef DEBUG static int const OUTGOING_CALL_WAKEUP_DELAY = 10;