【发布时间】:2011-12-20 01:04:15
【问题描述】:
我想知道在应用更新下载后如何再次调用 didFinishLaunchingWithOptions,因为我所有的函数调用都在那里。
当我从网上下载数据时,我需要再次调用self.dataArray = [self readDataJsonFromDocument];again。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self UIAppearances];
//first load
[self copyJsonFromBundle];
[self copyFolderFromBundle];
self.dataArray = [self readDataJsonFromDocument]; //i need to call this again
// Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//NSString *downloadFolder = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"download"];
//save to a temp file
NSString* filePath = [NSString stringWithFormat:@"%@/temp.zip", self.documentsDir];
//download folder
//NSString* downloadFolder = [NSString stringWithFormat:@"%@/download", self.documentsDir];
[self.fileManager createFileAtPath:filePath contents:self.receivedData attributes:nil];
ZipArchive *zipArchive = [[ZipArchive alloc] init];
if([zipArchive UnzipOpenFile:filePath]) {
// if ([zipArchive UnzipFileTo:downloadFolder overWrite:YES]) {
if ([zipArchive UnzipFileTo:self.documentsDir overWrite:YES]) {
//unzipped successfully
NSLog(@"Archive unzip Success");
[self.fileManager removeItemAtPath:filePath error:NULL];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
} else {
NSLog(@"Failure To Unzip Archive");
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
} else {
NSLog(@"Failure To Open Archive");
}
//[self performSelectorOnMainThread:@selector(didUpdate) withObject:nil waitUntilDone:YES];
//Update Document File
NSString *updateUTCPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"UTCDate"];
NSDate *currentDate = [NSDate date];
NSArray *array = [NSArray arrayWithObject:currentDate];
[array writeToFile:updateUTCPath atomically:YES];
}
【问题讨论】:
-
你永远不应该手动调用它。这是 iOS 调用的委托方法。您需要将调用放在自己的单独方法中,然后在需要时调用该方法。
-
我该怎么做?,刚刚用代码编辑了我的问题
标签: iphone objective-c ios cocoa-touch