iPhone(iOS):将文件从主文件夹复制到文件夹导致崩溃 - 代码日志

iPhone(iOS):将文件从主文件夹复制到文件夹导致崩溃

我正在尝试设置我的应用程序,以便在首次启动时,主包中“Populator”文件夹中的一系列文件被复制到documents目录中。

我目前的实施情况如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];
  NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];
  NSLog(@"Source Path: %@\n Documents Path: %@ \n Folder Path: %@", sourcePath, documentsDirectory, folderPath);

  NSError *error;

  [[NSFileManager defaultManager] copyItemAtPath:sourcePath 
                                        toPath:folderPath
                                         error:&error];

  NSLog(@"Error description-%@ \n", [error localizedDescription]);
  NSLog(@"Error reason-%@", [error localizedFailureReason]);
  ....
  return YES;
}

但是,第一次使用以下控制台消息运行时会崩溃(但是会复制文件)。下次打开应用程序时,它不会崩溃。

    2010-07-13 15:14:26.418 AppName[5201:207] Source Path: /Users/jack/Library/Application Support/iPhone Simulator/3.2/Applications/1076C1FA-60B0-4AC7-8CD4-74F81472DAE6/AppName.app/Populator
 Documents Path: /Users/jack/Library/Application Support/iPhone Simulator/3.2/Applications/1076C1FA-60B0-4AC7-8CD4-74F81472DAE6/Documents 
 Folder Path: /Users/jack/Library/Application Support/iPhone Simulator/3.2/Applications/1076C1FA-60B0-4AC7-8CD4-74F81472DAE6/Documents/Files
2010-07-13 15:14:26.466 AppName[5201:207] *** +[AppNameAppDelegate localizedDescription]: unrecognized selector sent to class 0xa79c
2010-07-13 15:14:26.475 AppName[5201:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[AppNameAppDelegate localizedDescription]: unrecognized selector sent to class 0xa79c'
2010-07-13 15:14:26.495 AppName[5201:207] Stack: (
    40911435,
    2569270537,
    41183227,
    40645910,
    40642578,
    9142,
    2815466,
    2819475,
    2844680,
    2826401,
    2858055,
    49271164,
    40452156,
    40448072,
    2817668,
    2850273,
    8776,
    8630
)

有没有人对于出现什么问题有任何建议?我已经有一些代码设置来实现“仅在第一次启动”功能,但是为了清楚起见,它没有包括在这里。

谢谢

我不太了解iPhone编程或客观C,但出于好奇,那么在这种情况下,如果复制操作实际上成功了呢?如果没有错误,它可能是崩溃的日志行?

另外,您是否允许复制这样的子目录的全部内容? (再次,我不熟悉iOS API,只是根据我所知道的其他语言/ API来确定可能的错误来源)

http://stackoverflow.com/questions/3238143/iphone-ios-copying-files-from-main-bundle-to-documents-folder-causes-crash

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:iPhone(iOS):将文件从主文件夹复制到文件夹导致崩溃