facebook twitter hatena line google mixi email

Ios/swift/画像保存

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

画像保存

       let ac = UIAlertController(title: "画像保存", message: "この画像を保存しますか?", preferredStyle: .Alert)
       let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in}
       let okAction = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
           UIImageWriteToSavedPhotosAlbum(self._imageView.image!, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
       }
       ac.addAction(cancelAction)
       ac.addAction(okAction)
       presentViewController(ac, animated: true, completion: nil)
   func image(image: UIImage, didFinishSavingWithError error: NSError!, contextInfo: UnsafeMutablePointer<Void>) {
       var title:String = "保存完了"
       var message:String = "アルバムへの保存完了"
       if error != nil {
           title = "エラー"
           message = "アルバムへの保存に失敗しました"
       }
       let alert:UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
       alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: {
           (action) -> Void in
           print("ok")
       }))
       self.presentViewController(alert, animated: true, completion: {})
   }

参考:http://swift-studying.com/blog/swift/?p=473