【问题标题】:how to call didFinishLaunchingWithOptions again after in app updates download如何在应用更新下载后再次调用 didFinishLaunchingWithOptions
【发布时间】:2011-12-20 01:04:15
【问题描述】:

我想知道在应用更新下载后如何再次调用 didFinishLaunchingWithOptions,因为我所有的函数调用都在那里。

当我从网上下载数据时,我需要再次调用self.dataArray = [self readDataJsonFromDocument];again。

- (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];

}

【问题讨论】:

  • 你永远不应该手动调用它。这是 iOS 调用的委托方法。您需要将调用放在自己的单独方法中,然后在需要时调用该方法。
  • 我该怎么做?,刚刚用代码编辑了我的问题

标签: iphone objective-c ios cocoa-touch


【解决方案1】:

你想做什么?

您当然可以手动第二次调用您的 App Delegate 的 didFinishLaunchingWithOptions 方法,但将您想要完成的所有功能放入其中可能更有意义第二次进入一个单独的函数,该函数由 附加到您的下载更新方法的委托和 didFinishLaunchingWithOptions 方法调用。

【讨论】:

  • 谢谢,我想再调用一次 self.dataArray = [self readDataJsonFromDocument];在 didFinishLaunchingWithOptions 里面
  • 然后将您的应用程序代理设置为处理下载更新的代码之一,一旦更新完成下载,您可以再次调用self.dataArray = [self readDataJsonFromDocument];。非常简单。
  • 我在 - (void)connectionDidFinishLoading:(NSURLConnection *)connection delegate 中做到了
  • 你能从connectionDidFinishLoading 方法的“成功下载”部分做self.dataArray = [self readDataJsonFromDocument]; 的事情吗?
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多