ioscordovadeep-linkingcordova-ios

iOS 14 Widget: Click item to open app page on Cordova


I have a Project which is build on Cordova, recently I have developed the widget for ios 14. Target: when the user click on the widget Article Item, I want console.log() or catch the URL on the Cordova project so that I can user redirect to the Article Page.

In the project Already code exist which takes care of deeplink. But whenever, I click on the widget item My app launches. For Example : if click on the article link from the Slack Application. User will land on the corresponding Article.

I am using this plugins cordova-universal-links-plugin, cordova-plugin-customurlscheme

Regarding the Widget Native code I followed the documentation Creating widget and i am using the Link method WidgetFamily.systemMedium or WidgetFamily.systemLarge, for other widgets i am using widgetURL(_:)

Link(destination: URL(string: urlString)!,label: {
                   Text(article.Title != nil ? article.Title! : "test")
                       .lineLimit(3)
                       .font(.system(size: 14, weight: .semibold, design: .default))
                       .padding()
               })

.widgetURL(URL(string: article.URL != nil ? article.URL! : ""))

on cordova APP I have

// Custom url scheme : cordova-plugin-customurlscheme
    window.handleOpenURL = url => {
      setTimeout(() => {
        main.onOpenApplicationLinks(url)
      }, 0)
    }
 // Universal Link Cordova Plugin
    universalLinks.subscribe('openPath', (eventData)=> console.log(eventData))

How can Catch the URL or Log the URL on the cordova App Thanks in Advance


Solution

  • After some days of research. I finally made change to the cordova-universalLink-Plugin. In plugin Appdelegate+CULPlugin.m add

    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
        if ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"]) {
            NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:NSUserActivityTypeBrowsingWeb];
            [activity setWebpageURL:url];
            
            CULPlugin *plugin = [self.viewController getCommandInstance:PLUGIN_NAME];
            return [plugin handleUserActivity:activity];
        }else{
            return NO;
        }
        
    }
    

    Voila...,now it works