Delegate after handle willFinishLaunchingWithOptions

Hi, I need to implement AppsFlyerTrackerDelegate inside extension for take conversion data from AppsFlyerSDK when app will finish launching.

SDK docs

My code:

#include "Utils.h"
#import <UIKit/UIKit.h>
#import <AppsFlyerLib/AppsFlyerTracker.h>

extern "C" void returnConversionSuccess (const char* data);
extern "C" void returnConversionError (const char* data);

@interface NMEAppDelegate : NSObject <UIApplicationDelegate, AppsFlyerTrackerDelegate>

@implementation NMEAppDelegate(UIApplicationDelegate)

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *) launchOptions
    [AppsFlyerTracker sharedTracker].delegate = self;
    return YES;

-(void)onConversionDataReceived:(NSDictionary*) installData
     returnConversionSuccess([resultString UTF8String]);

-(void)onConversionDataRequestFailure:(NSError *) error {
    NSLog(@"%@", error);
    NSString *resultString = [NSString stringWithFormat:@"%@", error];
    returnConversionError([resultString UTF8String]);


And when calling method returnConversionSuccess I got an BAD_ACCESS Error.
Debugger shows a string is not Null. Looks like my code has some troubles with delegate.
Also I tried to call returnConversionSuccess using performSelectorOnMainThread.
I’ll provide stack trace if you need. Thanks for your help.

I believe there was a solution to this in this Haxe Summit talk:

I am sorry that I do not have a solution handy and written down

There are also a lot of extensions under which may handle this, but I think the solution in the above video was cleaner?

thanks for your help, I checked out your links and finally found solution: before make callback just check you are in the main thread!

 if ([NSThread isMainThread]){
        returnConversionSuccess([resultString UTF8String]);
        dispatch_async(dispatch_get_main_queue(), ^{
            returnConversionSuccess([resultString UTF8String]);
1 Like