czwartek, 21 listopada 2013

How to load image from remote server on the UIImageView in iphone and save to application ?

Save An Image To Application Documents Folder From UIView On IOS.

//imageUrl =
-(NSString *)saveLocalImageFromUrl:(NSString *)imageUrl
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filename = [imageUrl lastPathComponent]; //get base file name
    NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:filename];
    NSString *foofile = [documentsDirectory stringByAppendingPathComponent:localFilePath];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];
    if(fileExists) {
        NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];
        [thedata writeToFile:localFilePath atomically:YES];
    return localFilePath;

Brak komentarzy:

Prześlij komentarz