|
7 | 7 | #import "gdp_converter.h"
|
8 | 8 |
|
9 | 9 |
|
| 10 | +struct DeeplinkServiceInitializer { |
| 11 | + DeeplinkServiceInitializer() { |
| 12 | + [GodotApplicalitionDelegate addService:[DeeplinkService shared]]; |
| 13 | + } |
| 14 | +}; |
| 15 | +static DeeplinkServiceInitializer initializer; |
| 16 | + |
| 17 | + |
10 | 18 | @implementation DeeplinkService
|
11 | 19 |
|
| 20 | +- (instancetype) init { |
| 21 | + self = [super init]; |
| 22 | + |
| 23 | + return self; |
| 24 | +} |
| 25 | + |
| 26 | ++ (instancetype) shared { |
| 27 | + static DeeplinkService* sharedInstance = nil; |
| 28 | + static dispatch_once_t onceToken; |
| 29 | + dispatch_once(&onceToken, ^{ |
| 30 | + sharedInstance = [[DeeplinkService alloc] init]; |
| 31 | + }); |
| 32 | + return sharedInstance; |
| 33 | +} |
| 34 | + |
12 | 35 | - (BOOL) application:(UIApplication*) app openURL:(NSURL*) url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*) options {
|
| 36 | + DeeplinkPlugin::receivedUrl = url; |
13 | 37 |
|
14 |
| - DeeplinkPlugin::get_singleton()->set_received_url(url); |
15 |
| - DeeplinkPlugin::get_singleton()->emit_signal(DEEPLINK_RECEIVED_SIGNAL, [GDPConverter nsUrlToGodotDictionary:url]); |
| 38 | + if (url) { |
| 39 | + NSLog(@"Deeplink plugin: URL received!"); |
| 40 | + } |
| 41 | + else { |
| 42 | + NSLog(@"Deeplink plugin: URL is empty!"); |
| 43 | + } |
| 44 | + |
| 45 | + DeeplinkPlugin* plugin = DeeplinkPlugin::get_singleton(); |
| 46 | + if (plugin) { |
| 47 | + plugin->emit_signal(DEEPLINK_RECEIVED_SIGNAL, [GDPConverter nsUrlToGodotDictionary:url]); |
| 48 | + } |
16 | 49 |
|
17 | 50 | return YES;
|
18 | 51 | }
|
19 | 52 |
|
20 | 53 | - (BOOL) application:(UIApplication*) app continueUserActivity:(NSUserActivity*) userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>>* restorableObjects)) restorationHandler {
|
21 | 54 | if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb]) {
|
22 |
| - NSURL* url = userActivity.webpageURL; |
23 |
| - DeeplinkPlugin::get_singleton()->set_received_url(url); |
24 |
| - DeeplinkPlugin::get_singleton()->emit_signal(DEEPLINK_RECEIVED_SIGNAL, [GDPConverter nsUrlToGodotDictionary:url]); |
25 |
| - } |
| 55 | + NSURL* url = userActivity.webpageURL; |
| 56 | + DeeplinkPlugin::receivedUrl = url; |
| 57 | + |
| 58 | + NSLog(@"Deeplink plugin: Deeplink received at app resumption!"); |
| 59 | + |
| 60 | + DeeplinkPlugin* plugin = DeeplinkPlugin::get_singleton(); |
| 61 | + if (plugin) { |
| 62 | + plugin->emit_signal(DEEPLINK_RECEIVED_SIGNAL, [GDPConverter nsUrlToGodotDictionary:url]); |
| 63 | + } |
| 64 | + } |
26 | 65 |
|
27 |
| - return YES; |
| 66 | + return YES; |
| 67 | +} |
| 68 | + |
| 69 | +- (BOOL) application:(UIApplication*) app didFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id>*) launchOptions { |
| 70 | + if (launchOptions) { |
| 71 | + NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey]; |
| 72 | + if (url) { |
| 73 | + NSLog(@"Deeplink plugin: Deeplink received at startup!"); |
| 74 | + DeeplinkPlugin::receivedUrl = url; |
| 75 | + |
| 76 | + DeeplinkPlugin* plugin = DeeplinkPlugin::get_singleton(); |
| 77 | + if (plugin) { |
| 78 | + plugin->emit_signal(DEEPLINK_RECEIVED_SIGNAL, [GDPConverter nsUrlToGodotDictionary:url]); |
| 79 | + } |
| 80 | + } |
| 81 | + else { |
| 82 | + NSLog(@"Deeplink plugin: UIApplicationLaunchOptionsURLKey is empty!"); |
| 83 | + |
| 84 | + NSDictionary* userActivityDict = [launchOptions objectForKey:UIApplicationLaunchOptionsUserActivityDictionaryKey]; |
| 85 | + if (userActivityDict) { |
| 86 | + url = [userActivityDict objectForKey:UIApplicationLaunchOptionsURLKey]; |
| 87 | + if (url) { |
| 88 | + NSLog(@"Deeplink plugin: Deeplink received at startup from user activity dictionary!"); |
| 89 | + DeeplinkPlugin::receivedUrl = url; |
| 90 | + |
| 91 | + DeeplinkPlugin* plugin = DeeplinkPlugin::get_singleton(); |
| 92 | + if (plugin) { |
| 93 | + plugin->emit_signal(DEEPLINK_RECEIVED_SIGNAL, [GDPConverter nsUrlToGodotDictionary:url]); |
| 94 | + } |
| 95 | + } |
| 96 | + else { |
| 97 | + NSLog(@"Deeplink plugin: UIApplicationLaunchOptionsURLKey is empty in user activity dictionary!"); |
| 98 | + |
| 99 | + NSUserActivity* userActivity = [userActivityDict objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"]; |
| 100 | + if (userActivity) { |
| 101 | + if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb]) { |
| 102 | + url = userActivity.webpageURL; |
| 103 | + DeeplinkPlugin::receivedUrl = url; |
| 104 | + |
| 105 | + NSLog(@"Deeplink plugin: Deeplink received at app startup from user activity!"); |
| 106 | + |
| 107 | + DeeplinkPlugin* plugin = DeeplinkPlugin::get_singleton(); |
| 108 | + if (plugin) { |
| 109 | + plugin->emit_signal(DEEPLINK_RECEIVED_SIGNAL, [GDPConverter nsUrlToGodotDictionary:url]); |
| 110 | + } |
| 111 | + } |
| 112 | + else { |
| 113 | + NSLog(@"Deeplink plugin: activity type is %@", userActivity.activityType); |
| 114 | + } |
| 115 | + } |
| 116 | + else { |
| 117 | + NSLog(@"Deeplink plugin: No user activity in user activity dictionary!"); |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + else { |
| 122 | + NSLog(@"Deeplink plugin: No user activity dictionary either!"); |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + else { |
| 127 | + NSLog(@"Deeplink plugin: launch options is empty!"); |
| 128 | + } |
| 129 | + |
| 130 | + return YES; |
28 | 131 | }
|
29 | 132 |
|
30 | 133 | @end
|
0 commit comments