Store image securely inside app document directory iOS swift

 Solution:


func saveImageDD(savingImage: UIImage) -> String{


        let urls = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroupname)


        let fileManager = FileManager.default

        let diceRoll = Int(arc4random_uniform(99999999))

        let name = "\(diceRoll).png"

        let paths = urls?.appendingPathComponent(name)

        let imageData = savingImage.jpegData(compressionQuality: 0.5)

        fileManager.createFile(atPath: (paths?.path)!, contents: imageData, attributes: nil)

        return name

}



The above code will store the image in document directory securely with appgroupname.


You cannot do this method in objective C.If you want to use this method in objective C then create delegate and call it inside objective c form swift code.



Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift