如何在应用程序更新下载后再次调用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]; } 

你想做什么?

您当然可以再次手动调用您的App Delegate的didFinishLaunchingWithOptions方法,但将其想要再次完成的所有function放入一个独立的函数中,可能会更有意义,该函数将被附加到您的下载的代理更新方法和didFinishLaunchingWithOptions方法。

您应该将您的代码抽象为另一种方法并调用该方法。 你不应该直接调用UIApplicationDelegate方法。