在我的didFinishLaunchingWithOptions 的appDelegate 中,我有以下内容:
NSURL *url = [NSURL URLWithString:@"http://www.thejenkinsinstitute.com/Journal/"];
NSString *content = [NSString stringWithContentsOfURL:url];
NSString * aString = content;
NSMutableArray *substrings = [NSMutableArray new];
NSScanner *scanner = [NSScanner scannerWithString:aString];
[scanner scanUpToString:@"<p>To Download the PDF, " intoString:nil]; // Scan all characters before #
while(![scanner isAtEnd]) {
NSString *substring = nil;
[scanner scanString:@"<p>To Download the PDF, <a href=\"" intoString:nil]; // Scan the # character
if([scanner scanUpToString:@"\"" intoString:&substring]) {
// If the space immediately followed the #, this will be skipped
[substrings addObject:substring];
}
[scanner scanUpToString:@"" intoString:nil]; // Scan all characters before next #
}
// do something with substrings
NSString *URLstring = [substrings objectAtIndex:0];
self.theheurl = [NSURL URLWithString:URLstring];
NSLog(@"%@", theheurl);
[substrings release];
theheurl 的控制台打印输出为我提供了一个以 .pdf 结尾的有效 URL。
在我想加载 URL 的类中,我有以下内容:
- (void)viewWillAppear:(BOOL)animated
{
_appdelegate.theheurl = currentURL;
NSLog(@"%@", currentURL);
NSLog(@"%@", _appdelegate.theheurl);
[worship loadRequest:[NSURLRequest requestWithURL:currentURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
[super viewWillAppear:YES];
}
但是,该类中的两个 NSLog 都返回 null。我在将 NSURL 从 AppDelegate 获取到类以加载它时做错了什么?