代码之家  ›  专栏  ›  技术社区  ›  iwasrobbed

尝试启动应用程序商店-获取“非结构或联合”错误中的“”。

  •  0
  • iwasrobbed  · 技术社区  · 16 年前

    我试图在不启动Safari和所有重定向的情况下启动应用程序商店,我得到一个关于“请求成员‘itunesurl’而不是结构或联合”的错误。

    我对很多事情都不熟悉,所以谢谢你对我耐心。我觉得这和我叫“self.itunesurl”有关,因为它不认为itunesurl是当前课程的一部分,但我可能是错的。

    在我(慢慢地)了解这一切的同时,提前感谢你的帮助。

    sampleapdelegate.h.示例

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

    sampleapdelegate.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];
    }
    

    我的视图控制器.h

    #import "SampleAppDelegate.h"
    

    而且我有 NSURL *iTunesURL; @interface 花括号。

    @property (nonatomic, retain) NSURL *iTunesURL;
    
    - (IBAction) proButtonPressed: (id)sender;  // press to launch App Store
    

    我的视图控制器.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 回复  |  直到 13 年前
        1
  •  1
  •   TechZen    16 年前

    iTunesURL 是的属性 ViewController 类,您只能使用 self 在该类的方法中引用。导入 ViewController.h 班级不给 SampleAppDelegate 类调用的属性的能力 视图控制器 类,除非它是 视图控制器 .

    您需要在 采样加速 并指定 ViewController.iTunesURL 到那个地方去。