diff --git a/RNCallKeep.podspec b/RNCallKeep.podspec index 821d4a50..be08dc18 100644 --- a/RNCallKeep.podspec +++ b/RNCallKeep.podspec @@ -13,6 +13,6 @@ Pod::Spec.new do |s| s.requires_arc = true s.platform = :ios, "8.0" s.source_files = "ios/RNCallKeep/*.{h,m}" - s.dependency 'React/Core' + s.dependency 'React-Core' end diff --git a/ios/RNCallKeep.xcodeproj/project.pbxproj b/ios/RNCallKeep.xcodeproj/project.pbxproj index c27ad33c..5dcf6cfd 100644 --- a/ios/RNCallKeep.xcodeproj/project.pbxproj +++ b/ios/RNCallKeep.xcodeproj/project.pbxproj @@ -61,7 +61,6 @@ 23DBCD111E13B465003D485F /* RNCallKeep.h */, 23DBCD121E13B465003D485F /* RNCallKeep.m */, ); - name = RNCallKeep; path = RNCallKeep; sourceTree = ""; }; @@ -92,7 +91,7 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 0810; - ORGANIZATIONNAME = "Wazo"; + ORGANIZATIONNAME = Wazo; TargetAttributes = { 234528911E0B88C700D1A033 = { CreatedOnToolsVersion = 8.1; @@ -105,6 +104,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 234528891E0B88C700D1A033; diff --git a/ios/RNCallKeep/RNCallKeep.h b/ios/RNCallKeep/RNCallKeep.h index 1c672b6b..40a2d72a 100644 --- a/ios/RNCallKeep/RNCallKeep.h +++ b/ios/RNCallKeep/RNCallKeep.h @@ -27,4 +27,10 @@ continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler; ++ (void)reportNewIncomingCall:(NSString *)uuidString + handle:(NSString *)handle + handleType:(NSString *)handleType + hasVideo:(BOOL)hasVideo + localizedCallerName:(NSString * _Nullable)localizedCallerName; @end + diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index a581728b..f82bd16c 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -29,11 +29,12 @@ @implementation RNCallKeep { - NSMutableDictionary *_settings; NSOperatingSystemVersion _version; BOOL _isStartCallActionEventListenerAdded; } +static CXProvider* sharedProvider; + // should initialise in AppDelegate.m RCT_EXPORT_MODULE() @@ -62,6 +63,7 @@ - (void)dealloc if (self.callKeepProvider != nil) { [self.callKeepProvider invalidate]; } + sharedProvider = nil; } // Override method of RCTEventEmitter @@ -79,6 +81,13 @@ - (void)dealloc ]; } ++ (void)initCallKitProvider { + if (sharedProvider == nil) { + NSDictionary *settings = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"RNCallKeepSettings"]; + sharedProvider = [[CXProvider alloc] initWithConfiguration:[RNCallKeep getProviderConfiguration:settings]]; + } +} + RCT_EXPORT_METHOD(setup:(NSDictionary *)options) { #ifdef DEBUG @@ -86,8 +95,14 @@ - (void)dealloc #endif _version = [[[NSProcessInfo alloc] init] operatingSystemVersion]; self.callKeepCallController = [[CXCallController alloc] init]; - _settings = [[NSMutableDictionary alloc] initWithDictionary:options]; - self.callKeepProvider = [[CXProvider alloc] initWithConfiguration:[self getProviderConfiguration]]; + NSDictionary *settings = [[NSMutableDictionary alloc] initWithDictionary:options]; + // Store settings in NSUserDefault + [[NSUserDefaults standardUserDefaults] setObject:settings forKey:@"RNCallKeepSettings"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + [RNCallKeep initCallKitProvider]; + + self.callKeepProvider = sharedProvider; [self.callKeepProvider setDelegate:self queue:nil]; } @@ -124,7 +139,7 @@ - (void)dealloc #ifdef DEBUG NSLog(@"[RNCallKeep][displayIncomingCall] uuidString = %@", uuidString); #endif - int _handleType = [self getHandleType:handleType]; + int _handleType = [RNCallKeep getHandleType:handleType]; NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init]; callUpdate.remoteHandle = [[CXHandle alloc] initWithType:_handleType value:handle]; @@ -155,7 +170,7 @@ - (void)dealloc #ifdef DEBUG NSLog(@"[RNCallKeep][startCall] uuidString = %@", uuidString); #endif - int _handleType = [self getHandleType:handleType]; + int _handleType = [RNCallKeep getHandleType:handleType]; NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; CXHandle *callHandle = [[CXHandle alloc] initWithType:_handleType value:handle]; CXStartCallAction *startCallAction = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:callHandle]; @@ -259,6 +274,32 @@ - (void)requestTransaction:(CXTransaction *)transaction }]; } ++ (void)reportNewIncomingCall:(NSString *)uuidString + handle:(NSString *)handle + handleType:(NSString *)handleType + hasVideo:(BOOL)hasVideo + localizedCallerName:(NSString * _Nullable)localizedCallerName +{ +#ifdef DEBUG + NSLog(@"[RNCallKeep][reportNewIncomingCall] uuidString = %@", uuidString); +#endif + int _handleType = [RNCallKeep getHandleType:handleType]; + NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; + CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init]; + callUpdate.remoteHandle = [[CXHandle alloc] initWithType:_handleType value:handle]; + callUpdate.supportsDTMF = YES; + callUpdate.supportsHolding = YES; + callUpdate.supportsGrouping = YES; + callUpdate.supportsUngrouping = YES; + callUpdate.hasVideo = hasVideo; + callUpdate.localizedCallerName = localizedCallerName; + + [RNCallKeep initCallKitProvider]; + [sharedProvider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:^(NSError * _Nullable error) { + if (error == nil) {} + }]; +} + - (BOOL)lessThanIos10_2 { if (_version.majorVersion < 10) { @@ -276,7 +317,7 @@ - (BOOL)containsLowerCaseLetter:(NSString *)callUUID return [regex numberOfMatchesInString:callUUID options:0 range:NSMakeRange(0, [callUUID length])] > 0; } -- (int)getHandleType:(NSString *)handleType ++ (int)getHandleType:(NSString *)handleType { int _handleType; if ([handleType isEqualToString:@"generic"]) { @@ -291,21 +332,21 @@ - (int)getHandleType:(NSString *)handleType return _handleType; } -- (CXProviderConfiguration *)getProviderConfiguration ++ (CXProviderConfiguration *)getProviderConfiguration:(NSDictionary*)settings { #ifdef DEBUG NSLog(@"[RNCallKeep][getProviderConfiguration]"); #endif - CXProviderConfiguration *providerConfiguration = [[CXProviderConfiguration alloc] initWithLocalizedName:_settings[@"appName"]]; + CXProviderConfiguration *providerConfiguration = [[CXProviderConfiguration alloc] initWithLocalizedName:settings[@"appName"]]; providerConfiguration.supportsVideo = YES; providerConfiguration.maximumCallGroups = 3; providerConfiguration.maximumCallsPerCallGroup = 1; providerConfiguration.supportedHandleTypes = [NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypePhoneNumber], [NSNumber numberWithInteger:CXHandleTypeEmailAddress], [NSNumber numberWithInteger:CXHandleTypeGeneric], nil]; - if (_settings[@"imageName"]) { - providerConfiguration.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:_settings[@"imageName"]]); + if (settings[@"imageName"]) { + providerConfiguration.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:settings[@"imageName"]]); } - if (_settings[@"ringtoneSound"]) { - providerConfiguration.ringtoneSound = _settings[@"ringtoneSound"]; + if (settings[@"ringtoneSound"]) { + providerConfiguration.ringtoneSound = settings[@"ringtoneSound"]; } return providerConfiguration; } @@ -469,7 +510,11 @@ - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *) #endif NSString *callUUID = [self containsLowerCaseLetter:action.callUUID.UUIDString] ? action.callUUID.UUIDString : [action.callUUID.UUIDString lowercaseString]; [self sendEventWithName:RNCallKeepPerformEndCallAction body:@{ @"callUUID": callUUID }]; - [action fulfill]; + double delayInSeconds = 3.0; + dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); + dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ + [action fulfill]; + }); } -(void)provider:(CXProvider *)provider performSetHeldCallAction:(CXSetHeldCallAction *)action diff --git a/package.json b/package.json index 61d5bed5..0d2453fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-callkeep", - "version": "2.0.3", + "version": "2.0.4", "description": "iOS 10 CallKit and Android ConnectionService Framework For React Native", "main": "index.js", "scripts": {},