开发者

Trying to launch App Store - getting ""in something not a structure or union" error

开发者 https://www.devze.com 2022-12-26 01:58 出处:网络
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 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" 开发者_JS百科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];

}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消