Troubleshooting
iOS Swizzling
- AppsFlyer Unity Plugin uses the iOS life cycle events for the SDK to work.
- The plugins uses UnityAppController for the lifecycle events to be invoked.
- Sometimes other plugins (Firebase, Facebook, ect) use the same UnityAppController, which creates conflicts in the lifecycle events.
- These events include didBecomeActive, didEnterBackground, didReceiveRemoteNotification, continueUserActivity and openURL.
- When a conflict occurs these methods may not be invoked.
- The solution provided by the AppsFlyer Unity Plugin is Swizzling.
- Starting from
v6.0.7
there is an option to enable swizzling automatically.
To enable Swizzling, you have 3 options:
- For versions up to
6.5.3
- From version
6.5.3
Using info .plist
- To enable swizzling, in the info.plist file, a boolean K/V called
AppsFlyerShouldSwizzle
should be set to 1 (true). - This will automatically enable swizzling and solve conflicts with other plugins.
- Validate that the code in the AppsFlyer+AppController is called on the native side.
- Comment out
IMPL_APP_CONTROLLER_SUBCLASS(AppsFlyerAppController)
in AppsFlyerAppController.mm.
Using a c# Script
- Create a new c# script. (we called ours AFUpdatePlist.cs)
- Place the script in a editor folder (Assets > Editor > AFUpdatePlist.cs)
- The code in the script should look like this:
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class MyBuildPostprocessor {
[PostProcessBuildAttribute]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
if (target == BuildTarget.iOS)
{
string plistPath = pathToBuiltProject + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
PlistElementDict rootDict = plist.root;
rootDict.SetBoolean("AppsFlyerShouldSwizzle", true);
File.WriteAllText(plistPath, plist.WriteToString());
Debug.Log("Info.plist updated with AppsFlyerShouldSwizzle");
}
}
}
- Validate that the code in the AppsFlyer+AppController is called on the native side.
- Comment out
IMPL_APP_CONTROLLER_SUBCLASS(AppsFlyerAppController)
in AppsFlyerAppController.mm.
Using macroprocessor
- Add the preprocessor macro flag
AFSDK_SHOULD_SWIZZLE=1
to the build settings of the project.
- Validate that the code in the AppsFlyer+AppController is called on the native side.
Updating the info.plist
In this example, we will update the info.plist to send SKAN postbacks to AppsFlyer, but the script can be adjusted to update any key in the info.plist
- Create a new c# script. (we called ours AFUpdatePlist.cs)
- Place the script in a editor folder (Assets > Editor > AFUpdatePlist.cs)
- The code in the script should look like this:
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class MyBuildPostprocessor
{
[PostProcessBuildAttribute]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
if (target == BuildTarget.iOS)
{
string plistPath = pathToBuiltProject + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
PlistElementDict rootDict = plist.root;
rootDict.SetString("NSAdvertisingAttributionReportEndpoint", "https://appsflyer-skadnetwork.com/");
/*** To add more keys :
** rootDict.SetString("<your key>", "<your value>");
***/
File.WriteAllText(plistPath, plist.WriteToString());
Debug.Log("Info.plist updated with NSAdvertisingAttributionReportEndpoint");
}
}
}
Updated about 1 year ago