You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LaunchOptions.m 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright @ 2018-present Atlassian Pty Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Intents/Intents.h>
  17. #import <React/RCTBridge.h>
  18. #import <React/RCTBridgeModule.h>
  19. @interface LaunchOptions : NSObject<RCTBridgeModule>
  20. @property (nonatomic, weak) RCTBridge *bridge;
  21. @end
  22. @implementation LaunchOptions
  23. RCT_EXPORT_MODULE();
  24. - (dispatch_queue_t)methodQueue {
  25. return dispatch_get_main_queue();
  26. }
  27. RCT_EXPORT_METHOD(getInitialURL:(RCTPromiseResolveBlock)resolve
  28. reject:(__unused RCTPromiseRejectBlock)reject) {
  29. id initialURL = nil;
  30. if (self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey]) {
  31. NSURL *url = self.bridge.launchOptions[UIApplicationLaunchOptionsURLKey];
  32. initialURL = url.absoluteString;
  33. } else {
  34. NSDictionary *userActivityDictionary
  35. = self.bridge.launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
  36. NSUserActivity *userActivity
  37. = [userActivityDictionary objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"];
  38. if (userActivity != nil) {
  39. NSString *activityType = userActivity.activityType;
  40. if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
  41. // App was started by opening a URL in the browser
  42. initialURL = userActivity.webpageURL.absoluteString;
  43. } else if ([activityType isEqualToString:@"INStartAudioCallIntent"]
  44. || [activityType isEqualToString:@"INStartVideoCallIntent"]) {
  45. // App was started by a CallKit Intent
  46. INIntent *intent = userActivity.interaction.intent;
  47. NSArray<INPerson *> *contacts;
  48. NSString *url;
  49. BOOL startAudioOnly = NO;
  50. if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
  51. contacts = ((INStartAudioCallIntent *) intent).contacts;
  52. startAudioOnly = YES;
  53. } else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
  54. contacts = ((INStartVideoCallIntent *) intent).contacts;
  55. }
  56. if (contacts && (url = contacts.firstObject.personHandle.value)) {
  57. initialURL
  58. = @{
  59. @"config": @{@"startAudioOnly":@(startAudioOnly)},
  60. @"url": url
  61. };
  62. }
  63. }
  64. }
  65. }
  66. resolve(initialURL != nil ? initialURL : (id)kCFNull);
  67. }
  68. @end