Skip to content

Commit

Permalink
Merge pull request #13 from AppsFlyerSDK/dev/RD-51316/strict-mode
Browse files Browse the repository at this point in the history
Dev/rd 51316/strict mode
  • Loading branch information
af-fess authored Nov 25, 2020
2 parents 47d06ed + 00b3602 commit 229568a
Show file tree
Hide file tree
Showing 35 changed files with 3,662 additions and 45 deletions.
17 changes: 0 additions & 17 deletions Classes/AppsFlyer/AppsFlyerX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,6 @@ bool AppsFlyerX::isUseUninstallSandbox() {
#endif
}

void AppsFlyerX::setAdvertiserId(const std::string& advertiserId) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// Not supported for Android
CCLOGWARN("%s", "setAdvertiserId is not supported for Android.");
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
return AppsFlyerXApple::setAdvertiserId(advertiserId);
#endif
}

std::string AppsFlyerX::advertiserId() {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// Not supported for Android
CCLOGWARN("%s", "advertiserId is not supported for Android.");
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
return AppsFlyerXApple::advertiserId();
#endif
}

void AppsFlyerX::setUserEmails(std::vector<std::string> userEmails, EmailCryptTypeX type) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
Expand Down
3 changes: 0 additions & 3 deletions Classes/AppsFlyer/AppsFlyerX.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ class AppsFlyerX {
static void setUseUninstallSandbox(bool setUseUninstallSandbox);
static bool isUseUninstallSandbox();

static void setAdvertiserId(const std::string& advertiserId);
static std::string advertiserId();

static void setUserEmails(std::vector<std::string> userEmails, EmailCryptTypeX type);

static void start();
Expand Down
3 changes: 0 additions & 3 deletions Classes/AppsFlyer/AppsFlyerXApple.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ class AppsFlyerXApple {
static void setUseUninstallSandbox(bool setUseUninstallSandbox);
static bool isUseUninstallSandbox();

static void setAdvertiserId(const std::string& advertiserId);
static std::string advertiserId();

static void setUserEmails(std::vector<std::string> userEmails, EmailCryptTypeX type);

static void start();
Expand Down
9 changes: 6 additions & 3 deletions Classes/AppsFlyer/AppsFlyerXApple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@
}

void AppsFlyerXApple::disableAdvertisingIdentifier(bool shouldDisable) {
[[AppsFlyerLib shared] setDisableAdvertisingIdentifier:shouldDisable];
if ([[AppsFlyerLib shared] respondsToSelector:@selector(disableAdvertisingIdentifier)])
[[AppsFlyerLib shared] setDisableAdvertisingIdentifier:shouldDisable];
}

bool AppsFlyerXApple::isDisabledAdvertisingIdentifier() {
return [[AppsFlyerLib shared] disableAdvertisingIdentifier];
if ([[AppsFlyerLib shared] respondsToSelector:@selector(disableAdvertisingIdentifier)])
return [[AppsFlyerLib shared] disableAdvertisingIdentifier];
}

void AppsFlyerXApple::setIsDebug(bool isDebug) {
Expand Down Expand Up @@ -305,7 +307,8 @@ - (void)didUpdateUserActivity:(NSUserActivity *)userActivity NS_AVAILABLE_IOS(9_
}

void AppsFlyerXApple::waitForATTUserAuthorizationWithTimeoutInterval(double timeoutInterval){
[[AppsFlyerLib shared] waitForATTUserAuthorizationWithTimeoutInterval:timeoutInterval];
if ([[AppsFlyerLib shared] respondsToSelector:@selector(waitForATTUserAuthorizationWithTimeoutInterval:)])
[[AppsFlyerLib shared] waitForATTUserAuthorizationWithTimeoutInterval:timeoutInterval];
}

void AppsFlyerXApple::setPhoneNumber(const std::string& phoneNumber){
Expand Down
36 changes: 36 additions & 0 deletions Classes/AppsFlyer/libAppsFlyer/AppsFlyerDeepLink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AFSDKDeeplink.h
// AppsFlyerLib
//
// Created by Andrii Hahan on 20.08.2020.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_NAME(DeepLink)
@interface AppsFlyerDeepLink : NSObject

- (nonnull instancetype)init NS_UNAVAILABLE;
+ (nonnull instancetype)new NS_UNAVAILABLE;

@property (readonly, nonnull) NSDictionary<NSString *, id> *clickEvent;
@property (readonly, nullable) NSString *deeplinkValue;
@property (readonly, nullable) NSString *matchType;
@property (readonly, nullable) NSString *clickHTTPReferrer;
@property (readonly, nullable) NSString *mediaSource;
@property (readonly, nullable) NSString *campaign;
@property (readonly, nullable) NSString *campaignId;
@property (readonly, nullable) NSString *afSub1;
@property (readonly, nullable) NSString *afSub2;
@property (readonly, nullable) NSString *afSub3;
@property (readonly, nullable) NSString *afSub4;
@property (readonly, nullable) NSString *afSub5;
@property (readonly) BOOL isDeferred;

- (NSString *)toString;

@end

NS_ASSUME_NONNULL_END
29 changes: 29 additions & 0 deletions Classes/AppsFlyer/libAppsFlyer/AppsFlyerDeepLinkResult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// AFSDKDeeplinkResult.h
// AppsFlyerLib
//
// Created by Andrii Hahan on 20.08.2020.
//

#import <Foundation/Foundation.h>

@class AppsFlyerDeepLink;

typedef NS_CLOSED_ENUM(NSUInteger, AFSDKDeepLinkResultStatus) {
AFSDKDeepLinkResultStatusNotFound,
AFSDKDeepLinkResultStatusFound,
AFSDKDeepLinkResultStatusFailure,
} NS_SWIFT_NAME(DeepLinkResultStatus);

NS_SWIFT_NAME(DeepLinkResult)
@interface AppsFlyerDeepLinkResult : NSObject

- (nonnull instancetype)init NS_UNAVAILABLE;
+ (nonnull instancetype)new NS_UNAVAILABLE;

@property(readonly) AFSDKDeepLinkResultStatus status;

@property(readonly, nullable) AppsFlyerDeepLink *deepLink;
@property(readonly, nullable) NSError *error;

@end
34 changes: 32 additions & 2 deletions Classes/AppsFlyer/libAppsFlyer/AppsFlyerLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
// AppsFlyerLib.h
// AppsFlyerLib
//
// AppsFlyer iOS SDK 6.0.3 (182)
// AppsFlyer iOS SDK 6.1.1 (33)
// Copyright (c) 2012-2020 AppsFlyer Ltd. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "AppsFlyerCrossPromotionHelper.h"
#import "AppsFlyerShareInviteHelper.h"
NS_ASSUME_NONNULL_BEGIN
#import "AppsFlyerDeepLinkResult.h"
#import "AppsFlyerDeepLink.h"

NS_ASSUME_NONNULL_BEGIN

// In app event names constants
#define AFEventLevelAchieved @"af_level_achieved"
Expand Down Expand Up @@ -140,6 +143,14 @@ typedef enum {
EmailCryptTypeSHA256 = 3
} EmailCryptType;

NS_SWIFT_NAME(DeepLinkDelegate)
@protocol AppsFlyerDeepLinkDelegate <NSObject>

@optional
- (void)didResolveDeepLink:(AppsFlyerDeepLinkResult *_Nonnull)result;

@end

/**
Conform and subscribe to this protocol to allow getting data about conversion and
install attribution
Expand Down Expand Up @@ -224,6 +235,7 @@ typedef enum {
*/
@property(nonatomic, strong) NSString * appleAppID;

#ifndef AFSDK_NO_IDFA
/**
AppsFlyer SDK collect Apple's `advertisingIdentifier` if the `AdSupport.framework` included in the SDK.
You can disable this behavior by setting the following property to YES
Expand All @@ -238,6 +250,8 @@ typedef enum {
- (void)waitForATTUserAuthorizationWithTimeoutInterval:(NSTimeInterval)timeoutInterval
NS_SWIFT_NAME(waitForATTUserAuthorization(timeoutInterval:));

#endif

@property(nonatomic) BOOL disableSKAdNetwork;

/**
Expand Down Expand Up @@ -289,6 +303,8 @@ NS_SWIFT_NAME(waitForATTUserAuthorization(timeoutInterval:));
*/
@property(weak, nonatomic) id<AppsFlyerLibDelegate> delegate;

@property(weak, nonatomic) id<AppsFlyerDeepLinkDelegate> deepLinkDelegate;

/**
In app purchase receipt validation Apple environment(production or sandbox). The default value is NO
*/
Expand Down Expand Up @@ -579,12 +595,26 @@ NS_SWIFT_NAME(logEvent(name:values:completionHandler:));
*/
@property(nonatomic, nullable) NSArray<NSString *> *sharingFilter;

@property(nonatomic) NSUInteger deepLinkTimeout;

/**
Block an events from being shared with any partner
This method overwrite -[AppsFlyerLib setSharingFilter:]
*/
-(void)setSharingFilterForAllPartners;

/**
Validate if URL contains certain string and append quiery
parameters to deeplink URL. In case if URL does not contain user-defined string,
parameters are not appended to the url.
@param containsString string to check in URL.
@param parameters NSDictionary, which containins parameters to append to the deeplink url after it passed validation.
*/
- (void)appendParametersToDeepLinkingURLWithString:(NSString *)containsString
parameters:(NSDictionary<NSString *, NSString*> *)parameters
NS_SWIFT_NAME(appendParametersToDeeplinkURL(contains:parameters:));

@end

NS_ASSUME_NONNULL_END
Binary file modified Classes/AppsFlyer/libAppsFlyer/libAppsFlyerLib.a
Binary file not shown.
144 changes: 144 additions & 0 deletions Classes/Strict/AppsFlyer/AppsFlyerProxyX.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
//
// Created by Maxim Shoustin on 10/9/17.
//

#include <string>
#include "AppsFlyerProxyX.h"
#include <typeinfo>
#include "../../cocos2d/cocos/platform/CCPlatformMacros.h"




#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

cocos2d::ValueMap getMapForCallback(JNIEnv *env, jobject attributionObject);

void setAttributionCallbackOnConversionDataReceived(
void (*callbackMethod)(cocos2d::ValueMap installData)) {
if (NULL == attributionCallbackOnConversionDataReceived) {
attributionCallbackOnConversionDataReceived = callbackMethod;
}
}

void setAttributionCallbackOnAppOpenAttribution(
void (*callbackMethod)(cocos2d::ValueMap attributionData)) {
if (NULL == attributionCallbackOnAppOpenAttribution) {
attributionCallbackOnAppOpenAttribution = callbackMethod;
}
}

void setAttributionCallbackOnConversionDataRequestFailure(
void (*callbackMethod)(cocos2d::ValueMap error)) {
if (NULL == attributionCallbackOnConversionDataRequestFailure) {
attributionCallbackOnConversionDataRequestFailure = callbackMethod;
}
}

void setAttributionCallbackOnAppOpenAttributionFailure(
void (*callbackMethod)(cocos2d::ValueMap error)) {
if (NULL == attributionCallbackOnAppOpenAttributionFailure) {
attributionCallbackOnAppOpenAttributionFailure = callbackMethod;
}
}

/**
* TODO: handle other types of data
* */
JNIEXPORT void JNICALL Java_com_appsflyer_AppsFlyer2dXConversionCallback_onInstallConversionDataLoadedNative
(JNIEnv *env, jobject obj, jobject attributionObject) {

if (NULL == attributionCallbackOnConversionDataReceived) {
return;
}
attributionCallbackOnConversionDataReceived(getMapForCallback(env, attributionObject));
}


JNIEXPORT void JNICALL Java_com_appsflyer_AppsFlyer2dXConversionCallback_onAppOpenAttributionNative
(JNIEnv *env, jobject obj, jobject attributionObject){
CCLOG("%s","Java_com_appsflyer_AppsFlyer2dXConversionCallback_onAppOpenAttributionNative is called");

if (NULL == attributionCallbackOnAppOpenAttribution) {
return;
}
attributionCallbackOnAppOpenAttribution(getMapForCallback(env, attributionObject));

}

JNIEXPORT void JNICALL Java_com_appsflyer_AppsFlyer2dXConversionCallback_onAttributionFailureNative
(JNIEnv *env, jobject obj, jobject stringError){

CCLOG("%s","Java_com_appsflyer_AppsFlyer2dXConversionCallback_onInstallConversionFailureNative is called");

if (NULL == attributionCallbackOnAppOpenAttributionFailure) {
return;
}
attributionCallbackOnAppOpenAttributionFailure(getMapForCallback(env,stringError));
}

JNIEXPORT void JNICALL Java_com_appsflyer_AppsFlyer2dXConversionCallback_onInstallConversionFailureNative
(JNIEnv *env, jobject obj, jobject stringError) {

CCLOG("%s","Java_com_appsflyer_AppsFlyer2dXConversionCallback_onInstallConversionFailureNative is called");

if (NULL == attributionCallbackOnConversionDataRequestFailure) {
return;
}

attributionCallbackOnConversionDataRequestFailure(getMapForCallback(env,stringError));
}


cocos2d::ValueMap getMapForCallback(JNIEnv *env, jobject attributionObject) {
jclass clsHashMap = env->GetObjectClass(attributionObject);
cocos2d::ValueMap map;
jmethodID midKeySet = env->GetMethodID(clsHashMap, "keySet", "()Ljava/util/Set;");

if (midKeySet == NULL) {
return map; /* method not found */
}

jobject objKeySet = env->CallObjectMethod(attributionObject, midKeySet);

//javap -s -p java.util.Set | grep -A 1 toArray
jclass clsSet = env->GetObjectClass(objKeySet);

jmethodID midToArray = env->GetMethodID(clsSet, "toArray", "()[Ljava/lang/Object;");

if (midToArray == NULL) {
return map; /* method not found */
}

jobjectArray arrayOfKeys = (jobjectArray) env->CallObjectMethod(objKeySet, midToArray);
int arraySize = env->GetArrayLength(arrayOfKeys);
jclass jBooleanClass = env->FindClass("java/lang/Boolean");
jclass jStringClass = env->FindClass("java/lang/String");

for (int i=0; i < arraySize; ++i){
jstring objKey = (jstring) env->GetObjectArrayElement(arrayOfKeys, i);
const char* c_string_key = env->GetStringUTFChars(objKey, 0);
jmethodID midGet = env->GetMethodID(clsHashMap, "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
jobject objValue = env->CallObjectMethod(attributionObject, midGet, objKey);
if (objValue == NULL) {
map[std::string(c_string_key)] = cocos2d::Value::Null;
}
else if (env->IsInstanceOf(objValue, jBooleanClass)){
jmethodID booleanValueMID = env->GetMethodID(jBooleanClass, "booleanValue", "()Z");
bool booleanValue = (bool) env->CallBooleanMethod(objValue, booleanValueMID);
map[std::string(c_string_key)] = booleanValue;
} else if (env->IsInstanceOf(objValue, jStringClass)){
jstring objString = (jstring)objValue;
const char *c_string_value = env->GetStringUTFChars(objString, 0);
map[std::string(c_string_key)] = c_string_value;
}

env->DeleteLocalRef(objValue);
}

return map;
}


#endif

Loading

0 comments on commit 229568a

Please sign in to comment.