Skip to content

[Discuss] ios 13 handle voip incoming push notification #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
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
2 changes: 1 addition & 1 deletion RNCallKeep.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 2 additions & 2 deletions ios/RNCallKeep.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
23DBCD111E13B465003D485F /* RNCallKeep.h */,
23DBCD121E13B465003D485F /* RNCallKeep.m */,
);
name = RNCallKeep;
path = RNCallKeep;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -92,7 +91,7 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Wazo";
ORGANIZATIONNAME = Wazo;
TargetAttributes = {
234528911E0B88C700D1A033 = {
CreatedOnToolsVersion = 8.1;
Expand All @@ -105,6 +104,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 234528891E0B88C700D1A033;
Expand Down
6 changes: 6 additions & 0 deletions ios/RNCallKeep/RNCallKeep.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

71 changes: 58 additions & 13 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@

@implementation RNCallKeep
{
NSMutableDictionary *_settings;
NSOperatingSystemVersion _version;
BOOL _isStartCallActionEventListenerAdded;
}

static CXProvider* sharedProvider;

// should initialise in AppDelegate.m
RCT_EXPORT_MODULE()

Expand Down Expand Up @@ -62,6 +63,7 @@ - (void)dealloc
if (self.callKeepProvider != nil) {
[self.callKeepProvider invalidate];
}
sharedProvider = nil;
}

// Override method of RCTEventEmitter
Expand All @@ -79,15 +81,28 @@ - (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
NSLog(@"[RNCallKeep][setup] options = %@", options);
#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];
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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"]) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand Down