views:

128

answers:

1

I am trying to launch the App Store without launching Safari with all the redirects and I am getting an error about "Request for member 'iTunesURL' in something not a structure or union."

I am new to a lot of this so thank you for being patient with me. I think it has something to do with me calling "self.iTunesURL" since it doesn't think iTunesURL is a part of the current class, but I could be very wrong.

Thank you in advance for your help while I am (slowly) learning all of this.

SampleAppDelegate.h

-(void)launchStore:(NSURL *)iTunesURL;
-(void)connectionDidFinishLoading:(NSURLConnection *)connection;

SampleAppDelegate.m

// Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle
- (void)launchStore:(NSURL *)iTunesURL {

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:iTunesURL] delegate:self startImmediately:YES];
[conn release];
}

// Save the most recent URL in case multiple redirects occur
// "iTunesURL" is an NSURL property in your class declaration
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response {
self.iTunesURL = [response URL];
return request;
}

// No more redirects; use the last URL saved
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[[UIApplication sharedApplication] openURL:self.iTunesURL];
}

MyViewController.h

#import "SampleAppDelegate.h"

and i have NSURL *iTunesURL; within the @interface curley braces.

@property (nonatomic, retain) NSURL *iTunesURL;

- (IBAction) proButtonPressed: (id)sender;  // press to launch App Store

MyViewController.m

#import "MyViewController.h"

@implementation MyViewController

@synthesize iTunesURL;

- (IBAction) proButtonPressed: (id) sender {

NSURL *iTunesLink = [NSURL URLWithString:@"actual http URL goes here"];
SampleAppDelegate *appDelegate = (SampleAppDelegate *)[[UIApplication sharedApplication] delegate];

[appDelegate launchStore:iTunesLink];

}
+1  A: 

iTunesURL is a property of the ViewController class and you can only use the self reference within the methods of that class. Importing the ViewController.h class doesn't give the SampleAppDelegate class the ability to call the properties of ViewController class unless it is a subclass of ViewController.

You need to create a new another property within SampleAppDelegate and assign the value of ViewController.iTunesURL to that property.

TechZen
Thanks for the clear description! Worked like a charm
iWasRobbed