0

別のフォルダーを作成し、それらのフォルダーに画像を追加し、そのフォルダー全体をGoogleドライブにアップロードする必要があるiPhoneアプリを作成しています。フォルダと画像を作成するにはどうすればよいですか。

前もって感謝します

4

2 に答える 2

1

フォルダの作成

        NSString  *pngPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"/WB/%@",self.viewIndex]];

        // Check if the directory already exists
        BOOL isDir;        
        BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:pngPath isDirectory:&isDir];
        if (exists) 
        {
            if (!isDir) 
            {
                NSError *error = nil;
                [[NSFileManager defaultManager]  removeItemAtPath:pngPath error:&error];
                // Directory does not exist so create it
                [[NSFileManager defaultManager] createDirectoryAtPath:pngPath withIntermediateDirectories:YES attributes:nil error:nil];
            }
        }
        else
        {
            // Directory does not exist so create it
            [[NSFileManager defaultManager] createDirectoryAtPath:pngPath withIntermediateDirectories:YES attributes:nil error:nil];
        }        

そのフォルダに画像を追加する

    NSString  *pngImagePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"/WB/%@/%d.png",self.viewIndex,lineIndex]];
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    self.curImage = UIGraphicsGetImageFromCurrentImageContext();
    [UIImagePNGRepresentation(self.curImage) writeToFile:pngImagePath atomically:YES];
    UIGraphicsEndImageContext();
于 2013-04-11T12:37:08.657 に答える
0

これを試して :

//ドキュメント ディレクトリに保存する場合

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];

NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm:ss"];

NSDate *now = [[NSDate alloc] init];

NSString *theDate = [dateFormat stringFromDate:now];
NSString *theTime = [timeFormat stringFromDate:now];

NSString *strImageName=[NSString stringWithFormat:@"Documents/MyPhotos/Dt%@%@.png",theDate,theTime];
strImageName=[strImageName stringByReplacingOccurrencesOfString:@"-" withString:@""];
strImageName=[strImageName stringByReplacingOccurrencesOfString:@":" withString:@""];

[self createDocumentDirectory:@"MyPhotos"];
NSString  *pngPath = [NSHomeDirectory()  stringByAppendingPathComponent:strImageName];
[UIImagePNGRepresentation(YourImageView.image) writeToFile:pngPath atomically:YES];





    -(void)createDocumentDirectory:(NSString*)pStrDirectoryName
    {
        NSString *dataPath = [self getDocumentDirectoryPath:pStrDirectoryName];

        if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
    [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:NULL];
    }

    -(NSString*)getDocumentDirectoryPath:(NSString*)pStrPathName
    {
NSString *strPath = @"";
        if(pStrPathName)
            strPath = [[kAppDirectoryPath objectAtIndex:0] stringByAppendingPathComponent:pStrPathName];

        return strPath;
    }

   //Get Photo Onebyone


    NSError *error = nil;
    NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self getDocumentDirectoryPath:@"MyPhotos"] error:&error];

    if (!error) {
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self ENDSWITH '.png'"];
        NSArray *imagesOnly = [dirContents filteredArrayUsingPredicate:predicate];

        for (int i=0;i<[imagesOnly count]; i++) {
            [arrSaveImage addObject:[imagesOnly objectAtIndex:i]];//Save in your array.
        }
    }
于 2013-04-11T13:30:23.127 に答える