1+ using System ;
12using System . Collections . Generic ;
23using UnityEngine ;
34
@@ -6,8 +7,11 @@ namespace AppsFlyerSDK
67 public class AppsFlyer : MonoBehaviour
78 {
89
9- public static readonly string kAppsFlyerPluginVersion = "6.0.7" ;
10-
10+ public static readonly string kAppsFlyerPluginVersion = "6.1.0" ;
11+ public static string CallBackObjectName = null ;
12+ private static EventHandler onRequestResponse ;
13+ private static EventHandler onInAppResponse ;
14+
1115
1216 /// <summary>
1317 /// Initialize the AppsFlyer SDK with your devKey and appID.
@@ -41,6 +45,12 @@ public static void initSDK(string devKey, string appID)
4145 /// </example>
4246 public static void initSDK ( string devKey , string appID , MonoBehaviour gameObject )
4347 {
48+
49+ if ( gameObject != null )
50+ {
51+ CallBackObjectName = gameObject . name ;
52+ }
53+
4454#if UNITY_IOS && ! UNITY_EDITOR
4555 AppsFlyeriOS . setAppsFlyerDevKey ( devKey ) ;
4656 AppsFlyeriOS . setAppleAppID ( appID ) ;
@@ -63,9 +73,9 @@ public static void initSDK(string devKey, string appID, MonoBehaviour gameObject
6373 public static void startSDK ( )
6474 {
6575#if UNITY_IOS && ! UNITY_EDITOR
66- AppsFlyeriOS . startSDK ( ) ;
76+ AppsFlyeriOS . startSDK ( onRequestResponse != null , CallBackObjectName ) ;
6777#elif UNITY_ANDROID && ! UNITY_EDITOR
68- AppsFlyerAndroid . startSDK ( ) ;
78+ AppsFlyerAndroid . startSDK ( onRequestResponse != null , CallBackObjectName ) ;
6979#else
7080
7181#endif
@@ -80,9 +90,9 @@ public static void startSDK()
8090 public static void sendEvent ( string eventName , Dictionary < string , string > eventValues )
8191 {
8292#if UNITY_IOS && ! UNITY_EDITOR
83- AppsFlyeriOS . sendEvent ( eventName , eventValues ) ;
93+ AppsFlyeriOS . sendEvent ( eventName , eventValues , onInAppResponse != null , CallBackObjectName ) ;
8494#elif UNITY_ANDROID && ! UNITY_EDITOR
85- AppsFlyerAndroid . sendEvent ( eventName , eventValues ) ;
95+ AppsFlyerAndroid . sendEvent ( eventName , eventValues , onInAppResponse != null , CallBackObjectName ) ;
8696#else
8797
8898#endif
@@ -475,6 +485,78 @@ public static void generateUserInviteLink(Dictionary<string, string> parameters,
475485
476486#endif
477487 }
488+
489+ /// <summary>
490+ /// Start callback event.
491+ /// </summary>
492+ public static event EventHandler OnRequestResponse
493+ {
494+ add
495+ {
496+ onRequestResponse += value ;
497+ }
498+ remove
499+ {
500+ onRequestResponse -= value ;
501+ }
502+ }
503+
504+ /// <summary>
505+ /// In-App callback event.
506+ /// </summary>
507+ public static event EventHandler OnInAppResponse
508+ {
509+ add
510+ {
511+ onInAppResponse += value ;
512+ }
513+ remove
514+ {
515+ onInAppResponse -= value ;
516+ }
517+ }
518+
519+ /// <summary>
520+ /// Used to accept start callback from UnitySendMessage on native side.
521+ /// </summary>
522+ public void inAppResponseReceived ( string response )
523+ {
524+ if ( onInAppResponse != null )
525+ {
526+ onInAppResponse . Invoke ( null , parseRequestCallback ( response ) ) ;
527+ }
528+ }
529+
530+ /// <summary>
531+ /// Used to accept in-app callback from UnitySendMessage on native side.
532+ /// </summary>
533+ public void requestResponseReceived ( string response )
534+ {
535+ if ( onRequestResponse != null )
536+ {
537+ onRequestResponse . Invoke ( null , parseRequestCallback ( response ) ) ;
538+ }
539+ }
540+
541+ private static AppsFlyerRequestEventArgs parseRequestCallback ( string response )
542+ {
543+ int responseCode = 0 ;
544+ string errorDescription = "" ;
545+
546+ try
547+ {
548+ Dictionary < string , object > dictionary = CallbackStringToDictionary ( response ) ;
549+ var errorResponse = dictionary . ContainsKey ( "errorDescription" ) ? dictionary [ "errorDescription" ] : "" ;
550+ errorDescription = ( string ) errorResponse ;
551+ responseCode = ( int ) ( long ) dictionary [ "statusCode" ] ;
552+ }
553+ catch ( Exception e )
554+ {
555+ AFLog ( "parseRequestCallback" , String . Format ( "{0} Exception caught." , e ) ) ;
556+ }
557+
558+ return new AppsFlyerRequestEventArgs ( responseCode , errorDescription ) ;
559+ }
478560
479561 /// <summary>
480562 /// Helper method to convert json strings to dictionary.
0 commit comments