Iphone 如何在应用内更新下载后再次调用didFinishLaunchingWithOptions
我想知道在应用程序内更新下载后如何再次调用didFinishLaunchingWithOptions,因为我所有的函数调用都在那里 我需要再次调用它Iphone 如何在应用内更新下载后再次调用didFinishLaunchingWithOptions,iphone,objective-c,ios,cocoa-touch,Iphone,Objective C,Ios,Cocoa Touch,我想知道在应用程序内更新下载后如何再次调用didFinishLaunchingWithOptions,因为我所有的函数调用都在那里 我需要再次调用它self.dataArray=[self-readDataJsonFromDocument]当我从网上下载数据时再次出现 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
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];
}
你想干什么
您当然可以手动调用您的应用程序代理的第二次使用Options
方法完成启动,但是,将您希望第二次完成的所有功能放在一个单独的函数中可能更有意义,该函数由附加到下载更新方法的代理和didfishlaunchingwithoptions方法调用。您应该将代码抽象到另一个方法中并调用该方法。您不应该直接调用UIApplicationLegate方法。您不应该手动调用它。这是iOS调用的委托方法。你需要把你的调用放在一个单独的方法中,然后在需要的时候调用这个方法。我怎么做?刚刚用CodesHanks编辑了我的问题,我想再次调用self.dataArray=[self-readDataJsonFromDocument];在DidFinishLaunchingWithOptions中,然后将你的应用程序委托也设置为处理下载更新的代码的委托,更新下载完成后,你可以调用self.dataArray=[self-readDataJsonFromDocument]代码>再次。非常简单。我是在-(void)connectiondFinishLoading:(NSURLConnection*)连接代理中完成的。您可以执行self.dataArray=[self-readDataJsonFromDocument]您的connectiondFinishLoading
方法的“成功下载”部分中的代码>内容?