Titanium中的Firebase动态链接问题

时间:2020-02-20 14:20:35

标签: android firebase titanium firebase-dynamic-links titanium-modules

我正在努力将Firebase动态链接添加到我的应用程序中。我已经创建了一个本机模块,可以在这里找到:Titanium Firebase DynamicLinks。该模块的核心方法是handleDeepLink()

@Kroll.method
    public void handleDeepLink() {
        Activity currentActivity = TiApplication.getAppRootOrCurrentActivity();
        Intent intent = currentActivity.getIntent();
        if (intent == null) {
            return;
        }
        Log.w(LCAT, "Links instance not null: " + (FirebaseDynamicLinks.getInstance() != null));
        Log.w(LCAT, "current activity not null: " + (currentActivity != null));
        FirebaseDynamicLinks.getInstance()
        .getDynamicLink(intent)
        .addOnSuccessListener(currentActivity, new OnSuccessListener<PendingDynamicLinkData>() {
            @Override
            public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                Uri deepLink = null;
                if (pendingDynamicLinkData != null) {
                    deepLink = pendingDynamicLinkData.getLink();

                    KrollDict queryParams = new KrollDict();
                    Set<String> queryParamNames = deepLink.getQueryParameterNames();
                    for (String paramName : queryParamNames) {
                        queryParams.put(paramName, deepLink.getQueryParameter(paramName));
                    }
                    fireEvent("deeplink:new", queryParams);
                }
            }
        })
        .addOnFailureListener(currentActivity, new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                fireEvent("deeplink:error", e.getMessage());
            }
        }); 
    }

我已将其添加到演示的Alloy应用程序中,并以以下方式使用它:

$.index.addEventListener('open', () => {
    const Firebase = require('com.pmitkowski.firebase.dynamiclinks');
    Firebase.addEventListener('deeplink:new', (params) => {
        console.warn('deep link params', params);
    });
    Firebase.addEventListener('deeplink:error', (error) => {
        console.error(error);
    });
    Firebase.handleDeepLink();
});

$.index.open();

我的index.xml文件:

<Alloy>
    <Window class="container">
        <Label id="label" onClick="doClick">Hello, World</Label>
    </Window>
</Alloy>

问题是,每次我在Android模拟器上运行我的应用程序时,都会收到错误消息:

[ERROR] V8Exception: Exception occurred at /alloy/controllers/index.js:74: Uncaught Error: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.dynamiclinks.FirebaseDynamicLinks.getDynamicLink(android.content.Intent)' on a null object reference

实际上,模块中的FirebaseDynamicLinks.getInstance()方法返回null,但这不是它应该如何工作的方式,我也不知道为什么会发生。我确定Firebase在调用此方法之前会初始化自身(我可以在日志中看到它)。您能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我不确定如何使用SDK版本8.3.1解决此问题,但是当我切换到9.0.0并通过Gradle导入Firebase Dynamic Links依赖关系而不是使用普通的.aar和.jar依赖关系时,它开始了工作正常。