如何在应用更新下载后再次调用didFinishLaunchingWithOptions

时间:2011-12-20 01:04:16

标签: iphone objective-c ios cocoa-touch

我想知道如何在应用更新下载后再次调用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];

}

2 个答案:

答案 0 :(得分:5)

你想做什么?

您当然可以 手动 再次调用您的App Delegate的didFinishLaunchingWithOptions方法,但是将所有功能放在一起可能会更有意义第二次进入一个单独的函数,该函数由两者附加到下载更新方法和didFinishLaunchingWithOptions方法的委托调用。

答案 1 :(得分:3)

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