我想知道如何在應用程序更新下載後再次調用didFinishLaunchingWithOptions,因爲我所有的函數調用都在那裏。如何在應用程序更新下載後再次調用didFinishLaunchingWithOptions
我需要再次調用這個self.dataArray = [self readDataJsonFromDocument];
當我從網上下載數據。
- (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調用的委託方法。您需要將自己的呼叫置於獨立的方法中,然後在需要時調用該方法。 – chown 2011-12-20 01:09:01
我該怎麼做?,編輯我的問題代碼 – Desmond 2011-12-20 01:53:44