[iOS] Simplify code
Share the code for extracting the URL for conference from a NSUserActivity.
This commit is contained in:
parent
fcd12a9cf6
commit
4898f81596
|
@ -120,46 +120,18 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
||||||
continueUserActivity:(NSUserActivity *)userActivity
|
continueUserActivity:(NSUserActivity *)userActivity
|
||||||
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler
|
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler
|
||||||
{
|
{
|
||||||
NSString *activityType = userActivity.activityType;
|
|
||||||
|
|
||||||
// XXX At least twice we received bug reports about malfunctioning loadURL
|
// XXX At least twice we received bug reports about malfunctioning loadURL
|
||||||
// in the Jitsi Meet SDK while the Jitsi Meet app seemed to functioning as
|
// in the Jitsi Meet SDK while the Jitsi Meet app seemed to functioning as
|
||||||
// expected in our testing. But that was to be expected because the app does
|
// expected in our testing. But that was to be expected because the app does
|
||||||
// not exercise loadURL. In order to increase the test coverage of loadURL,
|
// not exercise loadURL. In order to increase the test coverage of loadURL,
|
||||||
// channel Universal linking through loadURL.
|
// channel Universal linking through loadURL.
|
||||||
if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]
|
|
||||||
&& [self loadURLInViews:userActivity.webpageURL]) {
|
id url = [self conferenceURLFromUserActivity:userActivity];
|
||||||
|
|
||||||
|
if (url && [self loadURLObjectInViews:url]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for a CallKit intent.
|
|
||||||
if ([activityType isEqualToString:@"INStartAudioCallIntent"]
|
|
||||||
|| [activityType isEqualToString:@"INStartVideoCallIntent"]) {
|
|
||||||
INIntent *intent = userActivity.interaction.intent;
|
|
||||||
NSArray<INPerson *> *contacts;
|
|
||||||
NSString *url;
|
|
||||||
BOOL startAudioOnly = NO;
|
|
||||||
|
|
||||||
if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
|
|
||||||
contacts = ((INStartAudioCallIntent *) intent).contacts;
|
|
||||||
startAudioOnly = YES;
|
|
||||||
} else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
|
|
||||||
contacts = ((INStartVideoCallIntent *) intent).contacts;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contacts && (url = contacts.firstObject.personHandle.value)) {
|
|
||||||
// Load the URL contained in the handle.
|
|
||||||
[self loadURLObjectInViews:@{
|
|
||||||
@"config": @{
|
|
||||||
@"startAudioOnly": @(startAudioOnly)
|
|
||||||
},
|
|
||||||
@"url": url
|
|
||||||
}];
|
|
||||||
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [RCTLinkingManager application:application
|
return [RCTLinkingManager application:application
|
||||||
continueUserActivity:userActivity
|
continueUserActivity:userActivity
|
||||||
restorationHandler:restorationHandler];
|
restorationHandler:restorationHandler];
|
||||||
|
@ -359,6 +331,38 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary *)conferenceURLFromUserActivity:(NSUserActivity *)userActivity {
|
||||||
|
NSString *activityType = userActivity.activityType;
|
||||||
|
|
||||||
|
if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
||||||
|
// App was started by opening a URL in the browser
|
||||||
|
return @{ @"url" : userActivity.webpageURL.absoluteString };
|
||||||
|
} else if ([activityType isEqualToString:@"INStartAudioCallIntent"]
|
||||||
|
|| [activityType isEqualToString:@"INStartVideoCallIntent"]) {
|
||||||
|
// App was started by a CallKit Intent
|
||||||
|
INIntent *intent = userActivity.interaction.intent;
|
||||||
|
NSArray<INPerson *> *contacts;
|
||||||
|
NSString *url;
|
||||||
|
BOOL startAudioOnly = NO;
|
||||||
|
|
||||||
|
if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
|
||||||
|
contacts = ((INStartAudioCallIntent *) intent).contacts;
|
||||||
|
startAudioOnly = YES;
|
||||||
|
} else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
|
||||||
|
contacts = ((INStartVideoCallIntent *) intent).contacts;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contacts && (url = contacts.firstObject.personHandle.value)) {
|
||||||
|
return @{
|
||||||
|
@"config": @{@"startAudioOnly":@(startAudioOnly)},
|
||||||
|
@"url": url
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
+ (instancetype)viewForExternalAPIScope:(NSString *)externalAPIScope {
|
+ (instancetype)viewForExternalAPIScope:(NSString *)externalAPIScope {
|
||||||
return [views objectForKey:externalAPIScope];
|
return [views objectForKey:externalAPIScope];
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <Intents/Intents.h>
|
#import "JitsiMeetView+Private.h"
|
||||||
|
|
||||||
#import <React/RCTBridge.h>
|
#import <React/RCTBridge.h>
|
||||||
#import <React/RCTBridgeModule.h>
|
#import <React/RCTBridgeModule.h>
|
||||||
|
@ -36,6 +36,7 @@ RCT_EXPORT_MODULE();
|
||||||
RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve
|
RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve
|
||||||
reject:(__unused RCTPromiseRejectBlock)reject) {
|
reject:(__unused RCTPromiseRejectBlock)reject) {
|
||||||
id initialURL = nil;
|
id initialURL = nil;
|
||||||
|
|
||||||
if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) {
|
if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) {
|
||||||
NSURL *url = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
|
NSURL *url = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
|
||||||
initialURL = url.absoluteString;
|
initialURL = url.absoluteString;
|
||||||
|
@ -45,34 +46,7 @@ RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve
|
||||||
NSUserActivity *userActivity
|
NSUserActivity *userActivity
|
||||||
= [userActivityDictionary objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"];
|
= [userActivityDictionary objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"];
|
||||||
if (userActivity != nil) {
|
if (userActivity != nil) {
|
||||||
NSString *activityType = userActivity.activityType;
|
initialURL = [JitsiMeetView conferenceURLFromUserActivity:userActivity];
|
||||||
|
|
||||||
if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
|
|
||||||
// App was started by opening a URL in the browser
|
|
||||||
initialURL = userActivity.webpageURL.absoluteString;
|
|
||||||
} else if ([activityType isEqualToString:@"INStartAudioCallIntent"]
|
|
||||||
|| [activityType isEqualToString:@"INStartVideoCallIntent"]) {
|
|
||||||
// App was started by a CallKit Intent
|
|
||||||
INIntent *intent = userActivity.interaction.intent;
|
|
||||||
NSArray<INPerson *> *contacts;
|
|
||||||
NSString *url;
|
|
||||||
BOOL startAudioOnly = NO;
|
|
||||||
|
|
||||||
if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
|
|
||||||
contacts = ((INStartAudioCallIntent *) intent).contacts;
|
|
||||||
startAudioOnly = YES;
|
|
||||||
} else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
|
|
||||||
contacts = ((INStartVideoCallIntent *) intent).contacts;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (contacts && (url = contacts.firstObject.personHandle.value)) {
|
|
||||||
initialURL
|
|
||||||
= @{
|
|
||||||
@"config": @{@"startAudioOnly":@(startAudioOnly)},
|
|
||||||
@"url": url
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,4 +54,3 @@ RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue