2011-12-20 6 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

+0

どのように私はそれを行うのですか?コードで私の質問を編集しました – Desmond

答えて

6

何をしようとしていますか?

は、あなたは確かには手動アプリデリゲートのdidFinishLaunchingWithOptions前記第2の時間を呼び出すことができますが、それはおそらくあなたがによって呼び出される別の関数に二回目を行うことにしたいすべての機能を置くために、より理にかなってダウンロードの更新方法に添付されている代理人とdidFinishLaunchingWithOptionsメソッド。

+0

ありがとう、私はこれをもう一度呼びたいと思いますself.dataArray = [self readDataJsonFromDocument];その中にdidFinishLaunchingWithOptions – Desmond

+0

があります。その後、アップデートのダウンロードを処理するコードのためにアプリケーションデリゲートを設定し、アップデートがダウンロードされたら、再度 'self.dataArray = [self readDataJsonFromDocument];'を呼び出すことができます。かなり簡単。 –

+0

どうすればいいですか?コードで私の質問を編集しました – Desmond

3

コードを別のメソッドに抽象化し、そのメソッドを呼び出す必要があります。 UIApplicationDelegateメソッドを直接呼び出すべきではありません。

+0

私はそれをやっていますか?コードで私の質問を編集しました – Desmond

+0

これを行うには? –

関連する問題