Guest User

Untitled

a guest
Jul 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. - (void) writePhotoLocallyAndAddPlistFile:(UIImage*)image atImageId:(NSString*)image_id
  2. {
  3.  
  4. NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES);
  5. NSString *documentsDirectory = [paths objectAtIndex: 0];
  6. //documents directory
  7.  
  8.  
  9.  
  10. NSString *filename = [NSString stringWithFormat:@"%@.jpg", image_id] ;
  11. NSString *filepath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, filename] ;
  12.  
  13. // Save the image
  14. NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(image,1.0f)];
  15. [imageData writeToFile:filepath atomically:YES];
  16.  
  17.  
  18. //write the plist
  19. NSString *plistFile = [documentsDirectory stringByAppendingPathComponent: @"data.plist"];
  20. NSMutableArray *array = [[NSArray alloc] initWithContentsOfFile:plistFile];
  21.  
  22. NSLog(@"plist array : %@", array);
  23. [array insertObject:filename atIndex:0];
  24. NSLog(@"plist array : %@", array);
  25.  
  26. [array writeToFile:plistFile atomically:YES];
  27. }//endfunction
  28. #pragma mark -
Add Comment
Please, Sign In to add comment