IOS Local Storage sandbox (Document)

Source: Internet
Author: User
to save a picture for example: 1. Save

/**
 *  Save user Avatar * *
+ (NSString *) Saveuserimage: (UIImage *)
    image{nsstring; Gets the document path
    Nsarray *document = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
    NSString *path = [document objectatindex:0];
    Nsfilemanager *maneger = [Nsfilemanager Defaultmanager];
    NSString *documentpath = [path stringbyappendingpathcomponent:@ "Mxuserimagefile"];
    if (![ Maneger Fileexistsatpath:documentpath]) {
        [Maneger Createdirectoryatpath:documentpath Withintermediatedirectories:yes Attributes:nil Error:nil];
    }
    url = [documentpath stringbyappendingpathcomponent:@ "Userimage.jpeg"];
    NSData *imagedata = uiimagejpegrepresentation (image, 1.0);
    [ImageData Writetofile:url Atomically:yes];
    return @ "Documents/mxuserimagefile/userimage.jpeg";
}

2. Delete Direct call Remove method (here is simple to write)

[Maneger Removeitematpath:path Error:nil];

3. Using User.avatarurl is Documents/mxuserimagefile/userimage.jpeg

NSString *path = [Nshomedirectory () STRINGBYAPPENDINGPATHCOMPONENT:USER.AVATARURL];
    [_headerimage Setimage:[uiimage Imagewithcontentsoffile:path]];


Note: Using the document store does not save an absolute path, because the name applied to the sandbox will change.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.