fork download
  1. NSString *saveDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  2. saveDirectory = [saveDirectory stringByAppendingPathComponent:@"/my_images"];
  3. NSFileManager *fileManger = [NSFileManager defaultManager];
  4. if( ![fileManger createDirectoryAtPath:saveDirectory withIntermediateDirectories:YES attributes:nil error:nil]){
  5. NSLog(@"create directory fail : %@", self.localDirectoryPath);
  6. }
  7. NSString *webImagePath =@"https://w...content-available-to-author-only...m.tw/images/srpr/logo11w.png";
  8. NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:webImagePath]];
  9. if( imageData != nil){
  10. NSLog(@"image data isn't nil");
  11. }
  12. NSString *localImagePath = [saveDirectory stringByAppendingPathComponent:@"image.png"];
  13. NSError *error = nil;
  14. if( [imageData writeToFile:localImagePath options:NSDataWritingAtomic error:&error]){
  15. NSLog(@"writeToFile: success: %@", localImagePath);
  16. } else{
  17. NSLog(@"writeTofILE: failure: %@ - %@", localImagePath, [error localizedDescription]);
  18. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.m:1:2: error: unknown type name 'NSString'
prog.m:1:2: warning: implicit declaration of function 'NSSearchPathForDirectoriesInDomains' [-Wimplicit-function-declaration]
prog.m:1:65: error: 'NSDocumentDirectory' undeclared here (not in a function)
prog.m:1:86: error: 'NSUserDomainMask' undeclared here (not in a function)
prog.m:1:104: error: 'YES' undeclared here (not in a function)
prog.m:2:5: warning: data definition has no type or storage class [enabled by default]
prog.m:2:5: warning: type defaults to 'int' in declaration of 'saveDirectory' [enabled by default]
prog.m:2:5: error: conflicting types for 'saveDirectory'
prog.m:1:12: note: previous definition of 'saveDirectory' was here
prog.m:2:5: error: cannot find interface declaration for 'NSConstantString'
prog.m:2:5: warning: invalid receiver type 'int' [enabled by default]
prog.m:2:5: warning: no '-stringByAppendingPathComponent:' method found [enabled by default]
prog.m:2:5: warning: (Messages without a matching method signature [enabled by default]
prog.m:2:5: warning: will be assumed to return 'id' and accept [enabled by default]
prog.m:2:5: warning: '...' as arguments.) [enabled by default]
prog.m:3:5: error: unknown type name 'NSFileManager'
prog.m:3:34: error: 'NSFileManager' undeclared here (not in a function)
prog.m:4:5: error: expected identifier or '(' before 'if'
prog.m:7:5: error: unknown type name 'NSString'
prog.m:8:5: error: unknown type name 'NSData'
prog.m:8:26: error: 'NSData' undeclared here (not in a function)
prog.m:8:56: error: 'NSURL' undeclared here (not in a function)
prog.m:9:5: error: expected identifier or '(' before 'if'
prog.m:12:5: error: unknown type name 'NSString'
prog.m:12:5: warning: invalid receiver type 'int' [enabled by default]
prog.m:12:5: warning: no '-stringByAppendingPathComponent:' method found [enabled by default]
prog.m:13:5: error: unknown type name 'NSError'
prog.m:13:22: error: 'nil' undeclared here (not in a function)
prog.m:14:5: error: expected identifier or '(' before 'if'
prog.m:16:7: error: expected identifier or '(' before 'else'
stdout
Standard output is empty