Skip to content

Commit 69f5f1f

Browse files
authored
Merge pull request #46 from AppsFlyerSDK/releases/6.x.x/6.0.x/6.0.7
6.0.7
2 parents 2249289 + 6e72bee commit 69f5f1f

File tree

10 files changed

+115
-59
lines changed

10 files changed

+115
-59
lines changed

Assets/AppsFlyer/AppsFlyer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace AppsFlyerSDK
66
public class AppsFlyer : MonoBehaviour
77
{
88

9-
public static readonly string kAppsFlyerPluginVersion = "6.0.6";
9+
public static readonly string kAppsFlyerPluginVersion = "6.0.7";
1010

1111

1212
/// <summary>

Assets/AppsFlyer/Editor/AppsFlyerDependencies.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</androidPackages>
1212

1313
<iosPods>
14-
<iosPod name="AppsFlyerFramework" version="6.0.5" minTargetSdk="8.0">
14+
<iosPod name="AppsFlyerFramework" version="6.0.7" minTargetSdk="8.0">
1515
</iosPod>
1616
</iosPods>
1717

Assets/AppsFlyer/Plugins/iOS/AppsFlyer+AppController.m

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,33 @@ @implementation UnityAppController (AppsFlyerSwizzledAppController)
2727
+ (void)load {
2828
static dispatch_once_t onceToken;
2929
dispatch_once(&onceToken, ^{
30+
31+
id swizzleFlag = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppsFlyerShouldSwizzle"];
32+
BOOL shouldSwizzle = swizzleFlag ? [swizzleFlag boolValue] : NO;
3033

31-
/** <remove comment if you are swizzling applicationDidBecomeActive>
32-
Method method1 = class_getInstanceMethod([self class], @selector(applicationDidBecomeActive:));
33-
__original_applicationDidBecomeActive_Imp = method_setImplementation(method1, (IMP)__swizzled_applicationDidBecomeActive);
34-
*/
35-
36-
/** <remove comment if you are swizzling applicationDidEnterBackground>
37-
Method method2 = class_getInstanceMethod([self class], @selector(applicationDidEnterBackground:));
38-
__original_applicationDidEnterBackground_Imp = method_setImplementation(method2, (IMP)__swizzled_applicationDidEnterBackground);
39-
*/
40-
41-
/** <remove comment if you are swizzling didReceiveRemoteNotification>
42-
Method method3 = class_getInstanceMethod([self class], @selector(didReceiveRemoteNotification:));
43-
__original_didReceiveRemoteNotification_Imp = method_setImplementation(method3, (IMP)__swizzled_didReceiveRemoteNotification);
44-
*/
45-
46-
/** <remove comment if you are swizzling openURL>
47-
Method method4 = class_getInstanceMethod([self class], @selector(application:openURL:options:));
48-
__original_openUrl_Imp = method_setImplementation(method4, (IMP)__swizzled_openURL);
49-
*/
50-
51-
/** <remove comment if you are swizzling continueUserActivity>
52-
[self swizzleContinueUserActivity:[self class]];
53-
*/
54-
34+
if(shouldSwizzle){
35+
36+
Method method1 = class_getInstanceMethod([self class], @selector(applicationDidBecomeActive:));
37+
__original_applicationDidBecomeActive_Imp = method_setImplementation(method1, (IMP)__swizzled_applicationDidBecomeActive);
38+
39+
Method method2 = class_getInstanceMethod([self class], @selector(applicationDidEnterBackground:));
40+
__original_applicationDidEnterBackground_Imp = method_setImplementation(method2, (IMP)__swizzled_applicationDidEnterBackground);
41+
42+
43+
Method method3 = class_getInstanceMethod([self class], @selector(didReceiveRemoteNotification:));
44+
__original_didReceiveRemoteNotification_Imp = method_setImplementation(method3, (IMP)__swizzled_didReceiveRemoteNotification);
45+
46+
47+
Method method4 = class_getInstanceMethod([self class], @selector(application:openURL:options:));
48+
__original_openUrl_Imp = method_setImplementation(method4, (IMP)__swizzled_openURL);
49+
50+
51+
[self swizzleContinueUserActivity:[self class]];
52+
}
53+
5554
});
5655
}
5756

58-
/** <remove comment if you are swizzling continueUserActivity>
5957
+(void)swizzleContinueUserActivity:(Class)class {
6058

6159
SEL originalSelector = @selector(application:continueUserActivity:restorationHandler:);
@@ -71,70 +69,66 @@ +(void)swizzleContinueUserActivity:(Class)class {
7169
class_replaceMethod(class, originalSelector, (IMP)__swizzled_continueUserActivity, method_getTypeEncoding(swizzledMethod));
7270
}
7371
}
74-
75-
BOOL __swizzled_continueUserActivity(id self, SEL _cmd, UIApplication* application, NSUserActivity* userActivity, void (^restorationHandler)(NSArray*)) {
76-
NSLog(@"swizzled continueUserActivity");
77-
[[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
78-
79-
if(__original_continueUserActivity_Imp){
80-
return ((BOOL(*)(id, SEL, UIApplication*, NSUserActivity*))__original_continueUserActivity_Imp)(self, _cmd, application, userActivity);
81-
}
82-
83-
return YES;
84-
}
85-
86-
*/
87-
88-
/** <remove comment if you are swizzling applicationDidBecomeActive>
72+
73+
BOOL __swizzled_continueUserActivity(id self, SEL _cmd, UIApplication* application, NSUserActivity* userActivity, void (^restorationHandler)(NSArray*)) {
74+
NSLog(@"swizzled continueUserActivity");
75+
[[AppsFlyerLib shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
76+
77+
if(__original_continueUserActivity_Imp){
78+
return ((BOOL(*)(id, SEL, UIApplication*, NSUserActivity*))__original_continueUserActivity_Imp)(self, _cmd, application, userActivity);
79+
}
80+
81+
return YES;
82+
}
83+
84+
85+
8986
void __swizzled_applicationDidBecomeActive(id self, SEL _cmd, UIApplication* launchOptions) {
9087
NSLog(@"swizzled applicationDidBecomeActive");
9188

9289
if(didEnteredBackGround){
93-
[[[AppsFlyerLib shared] start];
90+
[[AppsFlyerLib shared] start];
9491
}
9592

9693
if(__original_applicationDidBecomeActive_Imp){
9794
((void(*)(id,SEL, UIApplication*))__original_applicationDidBecomeActive_Imp)(self, _cmd, launchOptions);
9895
}
9996
}
100-
*/
10197

102-
/** <remove comment if you are swizzling applicationDidEnterBackground>
98+
10399
void __swizzled_applicationDidEnterBackground(id self, SEL _cmd, UIApplication* application) {
104100
NSLog(@"swizzled applicationDidEnterBackground");
105101
didEnteredBackGround = YES;
106102
if(__original_applicationDidEnterBackground_Imp){
107103
((void(*)(id,SEL, UIApplication*))__original_applicationDidEnterBackground_Imp)(self, _cmd, application);
108104
}
109105
}
110-
*/
111106

112-
/** <remove comment if you are swizzling didReceiveRemoteNotification>
107+
113108
BOOL __swizzled_didReceiveRemoteNotification(id self, SEL _cmd, UIApplication* application, NSDictionary* userInfo,void (^UIBackgroundFetchResult)(void) ) {
114109
NSLog(@"swizzled didReceiveRemoteNotification");
115-
116-
[[AppsFlyerLib shared] handlePushNotification:userInfo];
117-
110+
111+
[[AppsFlyerLib shared] handlePushNotification:userInfo];
112+
118113
if(__original_didReceiveRemoteNotification_Imp){
119114
return ((BOOL(*)(id, SEL, UIApplication*, NSDictionary*, (UIBackgroundFetchResult)))__original_didReceiveRemoteNotification_Imp)(self, _cmd, application, userInfo, nil);
120115
}
121116
return YES;
122117
}
123-
*/
124118

125-
/** <remove comment if you are swizzling openURL>
119+
120+
126121
BOOL __swizzled_openURL(id self, SEL _cmd, UIApplication* application, NSURL* url, NSDictionary * options) {
127122
NSLog(@"swizzled openURL");
128-
[[AppsFlyerLib shared] handleOpenUrl:url options:options];
123+
[[AppsFlyerLib shared] handleOpenUrl:url options:options];
129124
if(__original_openUrl_Imp){
130125
return ((BOOL(*)(id, SEL, UIApplication*, NSURL*, NSDictionary*))__original_openUrl_Imp)(self, _cmd, application, url, options);
131126
}
132127
return YES;
133128
}
134-
*/
135129

136-
@end
137130

131+
@end
138132

139133

140134

Assets/AppsFlyer/Plugins/iOS/AppsFlyerAppController.mm

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ - (instancetype)init
3232
{
3333
self = [super init];
3434
if (self) {
35-
UnityRegisterAppDelegateListener(self);
35+
36+
id swizzleFlag = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppsFlyerShouldSwizzle"];
37+
BOOL shouldSwizzle = swizzleFlag ? [swizzleFlag boolValue] : NO;
38+
39+
if(!shouldSwizzle){
40+
UnityRegisterAppDelegateListener(self);
41+
}
3642
}
3743
return self;
3844
}

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Versions
22

3+
4+
## v6.0.7
5+
6+
* RD-49435 - ios swizzle options fix
7+
* iOS SDK Version - 6.0.7
8+
9+
310
## v6.0.6
411

512
* RD-48888 - continueUserActivity remove super call

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
### <a id="plugin-build-for"> This plugin is built for
2222

2323
- Android AppsFlyer SDK **v5.4.3**
24-
- iOS AppsFlyer SDK **v6.0.5**
24+
- iOS AppsFlyer SDK **v6.0.7**
2525

2626

2727

-367 KB
Binary file not shown.
367 KB
Binary file not shown.

deploy/build_unity_package.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ echo "Start Build for appsflyer-unity-plugin.unitypackage"
44

55
DEPLOY_PATH=outputs
66
UNITY_PATH="/Applications/Unity/Unity.app/Contents/MacOS/Unity"
7-
PACKAGE_NAME="appsflyer-unity-plugin-6.0.6.unitypackage"
7+
PACKAGE_NAME="appsflyer-unity-plugin-6.0.7.unitypackage"
88
mkdir -p $DEPLOY_PATH
99

1010

@@ -20,7 +20,7 @@ mkdir -p $DEPLOY_PATH
2020
Assets \
2121
$PWD/$DEPLOY_PATH/$PACKAGE_NAME \
2222
-quit \
23-
&& echo "package exported successfully to outputs/appsflyer-unity-plugin-6.0.6.unitypackage" \
23+
&& echo "package exported successfully to outputs/appsflyer-unity-plugin-6.0.7.unitypackage" \
2424
|| echo "Failed to export package. See create_unity_core.log for more info."
2525

2626

docs/iOS-Swizzling-Guide.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# iOS Swizzling Guide
2+
3+
* AppsFlyer Unity Plugin uses the [iOS life cycle](https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle) events for the SDK to work.
4+
* The plugins uses [UnityAppController](https://docs.unity3d.com/Manual/UnityasaLibrary-iOS.html) for the lifecycle events to be invoked.
5+
* Sometimes other plugins (Firebase, Facebook, ect) use the same UnityAppController, which creates conflicts in the lifecycle events.
6+
* These events include didBecomeActive, didEnterBackground, didReceiveRemoteNotification, continueUserActivity and openURL.
7+
* When a conflict occurs these methods may not be invoked.
8+
* The solution provided by the AppsFlyer Unity Plugin is [Swizzling](https://medium.com/rocknnull/ios-to-swizzle-or-not-to-swizzle-f8b0ed4a1ce6).
9+
* Starting from `v6.0.7` there is an option to enable swizzling automatically.
10+
* To enable swizzling, in the info.plist file, a boolean K/V called `AppsFlyerShouldSwizzle` should be set to 1 (true).
11+
* This will automatically enable swizzling and solve conflicts with other plugins.
12+
* This can also be accomplished on the c# side by following these steps:
13+
14+
1. Create a new c# script. (we called ours AFUpdatePlist.cs)
15+
2. Place the script in a editor folder (Assets > Editor > AFUpdatePlist.cs)
16+
3. The code in the script should look like this:
17+
18+
```c#
19+
using System.IO;
20+
using UnityEngine;
21+
using UnityEditor;
22+
using UnityEditor.Callbacks;
23+
using UnityEditor.iOS.Xcode;
24+
25+
public class MyBuildPostprocessor {
26+
27+
[PostProcessBuildAttribute]
28+
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) {
29+
30+
if (target == BuildTarget.iOS)
31+
{
32+
string plistPath = pathToBuiltProject + "/Info.plist";
33+
PlistDocument plist = new PlistDocument();
34+
plist.ReadFromString(File.ReadAllText(plistPath));
35+
36+
PlistElementDict rootDict = plist.root;
37+
rootDict.SetBoolean("AppsFlyerShouldSwizzle", true);
38+
39+
File.WriteAllText(plistPath, plist.WriteToString());
40+
41+
Debug.Log("Info.plist updated with AppsFlyerShouldSwizzle");
42+
}
43+
44+
}
45+
}
46+
```
47+
48+
4. Validate that the code in the [AppsFlyer+AppController](https://github.com/AppsFlyerSDK/appsflyer-unity-plugin/blob/master/Assets/AppsFlyer/Plugins/iOS/AppsFlyer%2BAppController.m) is called on the native side.
49+

0 commit comments

Comments
 (0)