我试图启动App Store而不启动带有所有重定向的Safari,我收到的错误是“请求成员'iTunesURL',而不是结构或联合。”
我是很多新手,所以感谢你对我有耐心。我认为它与我调用“self.iTunesURL”有关,因为它不认为iTunesURL是当前类的一部分,但我可能是非常错误的。
在我(慢慢)学习所有这些的同时,提前感谢您的帮助。
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"
我在NSURL *iTunesURL;
curley braces中有@interface
。
@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];
}
答案 0 :(得分:1)
iTunesURL
是ViewController
类的属性,您只能在该类的方法中使用self
引用。导入ViewController.h
类不会使SampleAppDelegate
类能够调用ViewController
类的属性,除非它是ViewController
的子类。
您需要在SampleAppDelegate
中创建新的另一个属性,并将ViewController.iTunesURL
的值分配给该属性。