Xcode7. To set info to add an app Transport Security Settings (Type dictionary) under this dictionary add allow arbitrary Loads (type is Boolean, Value is Yes), HTTP protocol
#import "ViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
@interface Viewcontroller ()
@property (Nonatomic,strong) UIView *naview;
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.naview = [[UIView alloc]initwithframe:cgrectmake (0, 0, Self.view.frame.size.width, 64)];
Self.naView.backgroundColor = [Uicolor colorwithred:0.21 green:0.54 blue:0.89 alpha:0.8];
[Self.view AddSubview:self.naView];
UIButton * button = [[UIButton alloc]initwithframe:cgrectmake (SELF.NAVIEW.FRAME.SIZE.WIDTH/2-75, 0, 150, 50)];
[Button settitle:@ "Save network Picture" Forstate:uicontrolstatenormal];
[Button addtarget:self action: @selector (Save) forcontrolevents:uicontroleventtouchupinside];
[Self.naview Addsubview:button];
}
-(void) save{
UIImage *image = [UIImage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:@ "http://pic25.nipic.com/ 20121209/9252150_194258033000_2.jpg "]];
[Self saveimage:image];
Uiimageview * ImageView = [[Uiimageview alloc]initwithframe:cgrectmake (0, Self.view.frame.size.width, 200)];
Imageview.image = image;
[Self.view Addsubview:imageview];
}
-(void) SaveImage: (uiimage*) image{
Alassetslibrary *library = [[Alassetslibrary alloc] init];
[Library Writeimagetosavedphotosalbum:[image Cgimage] Orientation: (alassetorientation) image.imageorientation completionblock:^ (Nsurl *asseturl, Nserror *error) {
if (Error) {
NSLog (@ "Save image fail:%@", error);
}else{
Uialertview *alter = [[Uialertview alloc] initwithtitle:@ "hint" Message:nil delegate:nil cancelbuttontitle:nil otherbuttontitles:@ "Save Success", Nil];
[Alter show];
}
}];
}
Assetslibrary download pictures from the Web, save to albums, save Web images,