通用链接 IOS9

Universal Links IOS9

Apple 似乎正在放弃通过链接打开应用程序的自定义方案机制。
使用自定义方案,如果您尝试打开由您的应用程序注册的自定义方案,应用程序将打开并且 javascript 函数 handleOpenURL 将处理调用。

Worklight 是否支持 IOS9 中的新 "Universal Links" 方法?

通用链接未作为 iOS 9 支持的一部分进行测试。如果需要链接,暂时继续使用自定义方案选项。

编辑:经过测试发现有效。

在我们的项目中,worklight 没有立即触发通用链接功能的 handleOpenURL 函数。

因此,我们使用了以下解决方案:

1) 原生层插件

MyAppDelegate+UniversalLinksPlugin.h

#import "rr.h"


@interface MyAppDelegate (UniversalLinksPlugin)

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler;

@end

MyAppDelegate+UniversalLinksPlugin.m

#import "rr.h"
#import <objc/runtime.h>

@implementation MyAppDelegate (UniversalLinksPlugin)

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {

    NSLog(@"Universal links plugin: starting application launch handling.");
    // ignore activities that are not for Universal Links
    if (![userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb] || userActivity.webpageURL == nil) {
        return NO;
    }

    NSString* url = [userActivity.webpageURL absoluteString];
    NSLog(@"Universal links plugin: the following url is used for the application launch %@", url);

    NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
    [data setValue:url forKey:@"url"];
    [[WL sharedInstance] sendActionToJS:@"handleURL" withData:data];

    return YES;
}

@end

2) config.xml 更新:

<feature name="UniversalLinksPlugin">
   <param name="ios-package" value="UniversalLinksPlugin"/>
</feature>

3) iphone/js/main.js 更新:

/**
 * UL links handling
 */
document.addEventListener("deviceready", function() {
    WL.App.addActionReceiver ("ULReceiver", function(received) {
        if (received.action === "handleURL") {
            WL.Logger.debug('Inside handle URL action receiver. Provided url: ' + received.data.url);
            handleOpenURL(received.data.url);
        }
    });

}, false);

就是这样。我真的希望这会对某人有所帮助)