2011-12-20 44 views
0

我想知道如何在應用程序更新下載後再次調用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]; 

} 
+1

您不應該手動調用它。這是iOS調用的委託方法。您需要將自己的呼叫置於獨立的方法中,然後在需要時調用該方法。 – chown 2011-12-20 01:09:01

+0

我該怎麼做?,編輯我的問題代碼 – Desmond 2011-12-20 01:53:44

回答

6

你想要做什麼?

可以肯定手動調用應用程序委託的didFinishLaunchingWithOptions方法的第二次,但它可能會更有意義,把所有你想要做第二次到一個單獨的函數被調用方式的功能均爲附加到您的下載更新方法和didFinishLaunchingWithOptions方法的代表。

+0

謝謝,我想再次調用self.dataArray = [self readDataJsonFromDocument];這是在didFinishLaunchingWithOptions – Desmond 2011-12-20 01:32:22

+0

然後設置您的應用程序委託也是處理下載更新的代碼之一,一旦更新完成下載,您可以再次調用'self.dataArray = [self readDataJsonFromDocument];'。非常簡單。 – 2011-12-20 01:43:09

+0

我該怎麼做呢?,只是用編碼編輯了我的問題 – Desmond 2011-12-20 01:52:43

3

您應該將代碼抽象爲另一種方法並調用該方法。你不應該直接調用UIApplicationDelegate方法。

+0

我該怎麼做?,只是用編碼編輯我的問題 – Desmond 2011-12-20 01:54:03

+0

如何做到這一點? – 2016-06-19 11:10:54

相關問題