AppsFlyerSDK / appsflyer-cordova-plugin

AppsFlyer plugin for Cordova
MIT License
37 stars 72 forks source link

[BUG] registerDeepLink (or registerOnAppOpenAttribution) not triggered on ios on 'cold' app start #167

Closed DontGiveAFck closed 3 years ago

DontGiveAFck commented 3 years ago

Report

Platform

iphone 12 (ios 14.4) ionic 5, capacitor 2 Xcode 12.4

Plugin Version

cordova-plugin-appsflyer-sdk: 6.2.60

On what Platform are you having the issue?

ios (on android everything works as expected)

What did you do?

I configured universal deep links for ios and app links for android.

When I open universal link on ios (iphone 12, v14.4) device with fully closed application (app not running on background) - app opened but registerDeepLink or registerOnAppOpenAttribution not called.

Although if app not installed link redirects me to app store and after app installation registerDeepLink called. Also it called when I open link when app is running on background.

What did you expect to happen?

registerDeepLink should be called if I open installed app via universal link.

What happened instead?

App opened but registerDeepLink not called.

Please provide any other relevant information.

Appsflyer init:

const onSuccess = (res) => {
          try {
            // for some reason can be object or serialized object
            const conversionData = JSON.parse(res);
            const data = isJsonString(conversionData.data)
              ? JSON.parse(conversionData.data)
              : conversionData.data;

            const shouldHandleDeepLinks = data.is_first_launch;
            if (shouldHandleDeepLinks) {
              handleDeepLinks(data);
            }
          } catch (error) {
            console.error('Appsflyer initSdk onSuccess error: ', error);
          }
  };

  appsFlyer.registerDeepLink((res) => {
         try {
            const parsedRes = isJsonString(res) ? JSON.parse(res) : res;
            const data = isJsonString(parsedRes.data)
              ? JSON.parse(parsedRes.data)
              : parsedRes.data;
            handleDeepLinks(data);
          } catch (error) {
            console.error('registerDeepLink error: ', error);
          }
        });

        try {
          const options = {
            devKey: 'dev key',
            isDebug: !environment.production,
            appId: '123123123',
            onDeepLinkListener: true,
            onInstallConversionDataListener: true
          };

          appsFlyer.initSdk(options, isAndroid ? onSuccess : () => {});
        } catch (error) {
          console.error('appsFlyer.initSdk error', error);
        }
  });

AppDelegate.swift:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FBSDKCoreKit.ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
    return true
  }

  /* --- Open Universal Links --- */

  func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    // Called when the app was launched with an activity, including Universal Links.
    // Feel free to add additional processing here, but if you want the App API to support
    // tracking app url opens, make sure to keep this call
    AppsFlyerLib.shared().continue(userActivity, restorationHandler: nil)
    return true
  }

  /* --- END --- */

  /* --- Open Deeplinks --- */

  // Open URI-scheme for iOS 8 and below
  func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    AppsFlyerLib.shared().handleOpen(url, sourceApplication: sourceApplication, withAnnotation: annotation)
    return true
  }

  // Open URI-scheme for iOS 9 and above
  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    // Called when the app was launched with a url. Feel free to add additional processing here,
    // but if you want the App API to support tracking app url opens, make sure to keep this call
    AppsFlyerLib.shared().handleOpen(url, options: options)
    return true
  }

  /* --- END --- */

AppDebug.entitlements :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.developer.applesignin</key>
    <array>
        <string>Default</string>
    </array>
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:<domain here>.onelink.me</string>
    </array>
</dict>
</plist>
pazlavi commented 3 years ago

Hi @DontGiveAFck Thank you for reaching out to us.

In AppDelegate.swift please replace AppsFlyerLib with AppsFlyerAttribution. If the class is not found in Swift, you should create a Swift Bridging Header and add the next import to the file you created #import <AppsFlyerPlugin.h>

DontGiveAFck commented 3 years ago

image image image

@amit-kremer93 @pazlavi after adding Bridging file getting No such module 'AppsFlyerAttribution' error in AppDelegate.swift file

pazlavi commented 3 years ago

You should import AppsFlyerPlugin

DontGiveAFck commented 3 years ago

@pazlavi the same error for AppsFlyerPlugin image

pazlavi commented 3 years ago

Please make sure to build the project first. After you build the project, you probably be able to use the class directly (without the import in AppDelegate)

DontGiveAFck commented 3 years ago

@pazlavi you were right, now I'm able to use AppsFlyerAttribution, I did changes, but initial issue still exists - registerDeepLink not triggered on 'cold' ios app start current AppDelegate.swift file: image

pazlavi commented 3 years ago

The issue is that you provide nil as the restorationHandler. To enable a nil restorationHandler, please change this line in our plugin file to else if(self.userActivity).

gelinger777 commented 3 years ago

I have the same problem on iOS 14.4 with ionic cordova .

I have added the required Plugin + Code part ( I have left out only the part for ios less than 8)

But UDL data is not passed when I click the link. Link click opens the app, but not passing variables.

Could you hint why @pazlavi ?

here is my AppDelegate.m

 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 */

//
//  AppDelegate.m
//  Dignisi
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#import "AppDelegate.h"
#import "MainViewController.h"
#import "AppsFlyerPlugin.h"
#import <AppTrackingTransparency/AppTrackingTransparency.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    self.viewController = [[MainViewController alloc] init];
    if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            //If you want to do something with the pop-up
        }];
    }
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

// Deep linking
// Open URI-scheme for iOS 9 and above
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
    // version >= 6.2.30
    [[AppsFlyerAttribution shared] handleOpenUrl:url options:options];

    // version < 6.2.30
    [[AppsFlyerLib shared] handleOpenUrl:url options:options];
    return YES;
}

// Open Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
    // version >= 6.2.30
    [[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];

    //version < 6.2.30
    [[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
    return YES;
}
@end
pazlavi commented 3 years ago

Hi @gelinger777, What is the plugin version you are using?

If you are using V6.3.00 and above, please check this guide (Not need to add any code to AppDelegate.m)

For V6.2.30 up to V6.2.60:

// Deep linking
// Open URI-scheme for iOS 9 and above
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
    [[AppsFlyerAttribution shared] handleOpenUrl:url options:options];

    return YES;
}

// Open Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
    [[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];

    return YES;
}

Below V6.2.30:

// Deep linking
// Open URI-scheme for iOS 9 and above
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
    [[AppsFlyerLib shared] handleOpenUrl:url options:options];
    return YES;
}

// Open Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
    [[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
    return YES;
}

If any additional assistance is required here, we kindly ask you to submit a support ticket to support@appsflyer.com.

When submitting the ticket, please specify your AppsFlyer sign-up (account) email, app ID, reproduction steps, code snippets, logs, the links you used, and any additional relevant information.