BranchMetrics / cordova-ionic-phonegap-branch-deep-linking-attribution

The Branch Cordova Ionic Phonegap SDK for deep linking and attribution. Branch helps mobile apps grow with deep links / deeplinks that power paid acquisition and re-engagement campaigns, referral programs, content sharing, deep linked emails, smart banners, custom user onboarding, and more.
https://docs.branch.io/apps/cordova-phonegap-ionic/
MIT License
234 stars 144 forks source link

Warning. Session initialization already happened. To force a new session, set intent extra, "branch_force_new_session", to true. #653

Open ShayShaked opened 4 years ago

ShayShaked commented 4 years ago

Hi, We're facing a problem with the latest release Cordova 4.1.3 . When the app is initialized, every resume we get this error what causes the app to work unexpectedly: _error":"Warning. Session initialization already happened. To force a new session, set intent extra, \"branch_force_newsession\", to true.

I saw that the problem occurres also on android-branch-deep-linking-attribution , Android SDK v4.3.2. Is there any fix on the way?

env info Ionic:

Ionic CLI : 5.2.4 Ionic Framework : @ionic/angular 4.7.4 @angular-devkit/build-angular : 0.802.1 @angular-devkit/schematics : 8.2.1 @angular/cli : 8.2.1 @ionic/angular-toolkit : 2.0.0

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1)

Update 15/02/2021 There is an issue with location permission. When Location permission is Disabled the InitSession runs twice, what cause the Session initialization already happened error. If the Location permission is Enabled the initSession run only once

PDLMobileApps commented 4 years ago

We are facing the same issue with:

Cordova CLI: 9.0.0 cordova-android: 9.0.0 cordova-ios: 6.1.0

mifkys commented 4 years ago

Hello! I fixed this issue by replacing SessionListener.onInitFinished() method with next:

public void onInitFinished(JSONObject referringParams, BranchError error) {

            String out;

            if (error == null && referringParams != null) {
                if (this._callbackContext != null) {
                    this._callbackContext.success(referringParams);
                }
            } else {
                // fix ERR_BRANCH_ALREADY_INITIALIZED error
                if (error.getErrorCode() == BranchError.ERR_BRANCH_ALREADY_INITIALIZED) {
                  getLatestReferringParams(this._callbackContext);
                } else {
                    JSONObject message = new JSONObject();
                    try {
                        message.put("error", error.getMessage());
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    if (this._callbackContext != null) {
                        this._callbackContext.error(message);
                    }
                }
            }
        }