Question

I am not a good IOS developer (mostly do web stuff) but was given this task to do for work. The part concept is the app must load a webapp within a webview. This I have managed to do. Then next was getting referral info into the app which must be concatenated to the webapp's url before loading it up. I succeeded in getting the referral info into my app using Appsflyer (for anyone who works with affiliates this is cool) and now I'm stuck as one of the ways I tried was to store the info using NSUserDefaults in my delegate and call it before I load up the url but it doesn't always finish in time.

Here is my viewWillAppear

    - (void) viewWillAppear:(BOOL)animated
     {
       _webview.scrollView.bounces = NO;
       _webview.backgroundColor = [UIColor grayColor];
       _webview.opaque=NO;
       _webview.scalesPageToFit = YES;
       NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
       NSArray *btags = [prefs arrayForKey:@"banner"];
       NSLog(@"%@", btags);
       NSString *neededstring = [btags objectAtIndex:0];
       NSString *ourURL = @"http://mydomain.com?ref=";
       ourURL = [ourURL stringByAppendingString:neededstring];
       NSLog(@"%@", ourURL);
       NSURL *url = [NSURL URLWithString: ourURL];
       NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
       NSLog(@"Loading url");
       [_webview loadRequest:requestObj];
    }

Here is my AppDelegates onConversionDataReceived method

    -(void)onConversionDataReceived:(NSDictionary*) installData {
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];  //load NSUserDefaults
      id status = [installData objectForKey:@"af_status"];
      if([status isEqualToString:@"Non-organic"]) {
        id pid = [installData objectForKey:@"pid"];
        id campaign = [installData objectForKey:@"c"];
        id landingPage = [installData objectForKey:@"af_sub1"];
        NSLog(@"None organic istall pid=%@  campaign=%@ landing page:%@", pid, campaign, landingPage);
        NSLog(@"here");
        NSMutableArray *tags = [ NSMutableArray arrayWithObjects:pid,campaign, nil];  //declare array to be stored in NSUserDefaults
        [prefs setObject:tags forKey:@"banner"];  //set the prev Array for key value "favourites"
      }else if([status isEqualToString:@"Organic"]) {
        NSLog(@"organic");
        // handle organic install
        NSString *pid = @"6544581";
        NSMutableArray *tags = [NSMutableArray arrayWithObjects:pid, nil];
        [prefs setObject:tags forKey:@"banner"];
      } else {
        // not expecting to be here
    }
}

Another thought I had was creating a additional viewcontroller that runs before this viewcontroller but the problem still exists that what happens if the referral info doesn't get through in time.

If anyone could perhaps show me some light I'd much appreciate it.

Thank you :)

Was it helpful?

Solution

You should call

[prefs synchronize];

after you 'setObject: forKey:' in the preferences if you want the effect to be immediate. Also, you could instantiate the initial View Controller from the AppDelegate and create some custom properties that you would set in there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top