iOS開發 模擬器導入視頻、圖片資源

  • 方法一、直接將圖片/視頻拖拽到模擬器
  • 方法二、將資源文件通過代碼統一寫入

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    
    // 導入圖片
    NSString *picPath = [[NSBundle mainBundle] pathForResource:@"Pic" ofType:@"bundle"];
    NSDirectoryEnumerator *picEnumerator = [fileManager enumeratorAtPath:picPath];
    NSString *picBundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Pic.bundle"];
    while((picPath = [picEnumerator nextObject]) != nil) {
        NSString *itemPicPath = [NSString stringWithFormat:@"%@/%@", picBundlePath, picPath];
        UIImage *image = [UIImage imageWithContentsOfFile:itemPicPath];
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    }
    
    // 導入視頻
    NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"Video" ofType:@"bundle"];
    NSString *videoBundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Video.bundle"];
    NSDirectoryEnumerator *videoEnumerator = [fileManager enumeratorAtPath:videoPath];
    while ((videoPath = [videoEnumerator nextObject]) != nil) {
        NSString *itemVideoPath = [NSString stringWithFormat:@"%@/%@", videoBundlePath, videoPath];
        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(itemVideoPath)) {
            UISaveVideoAtPathToSavedPhotosAlbum(itemVideoPath, nil, nil, nil);
        }
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章