LoginSignup
2
4

More than 5 years have passed since last update.

Swift3 - 変数に入ったUIImageをLINEに投稿する方法

Last updated at Posted at 2017-03-18

えーっとですね、こちらのサイトを参考に画像をLINEにシェアさせたいんですけど、残念ながらStringしか入りませんで、僕が入れたいのは、変数の中に入ったUIImageの型なのです(アプリの中で動的に変数の中の画像の名前が変わるからです)。若干苦戦しましたが下記のコードで、ちゃんとUIImageをLINEにシェアできたよ。大切なコードの場所は ここpastBoard.setData(UIImageJPEGRepresentation(ImageHensu!, 1.0)!, forPasteboardType: "public.png")です。下記のコードをそのまんま@IBActionUIButtonの中にでも貼り付ければ動くはず

実装

        let pastBoard: UIPasteboard = UIPasteboard.general

//        pastBoard.setData(UIImageJPEGRepresentation(UIImage(named:  (ShareToImage) )!, 0.75)!, forPasteboardType: "public.png")

//        pastBoard.setDataUIImageJPEGRepresentation(ShareToImage, 1.0);, forPasteboardType: "public.png")

        pastBoard.setData(UIImageJPEGRepresentation(ImageHensu!, 1.0)!, forPasteboardType: "public.png")

        let lineUrlString: String = String(format: "line://msg/image/%@", pastBoard.name as CVarArg)

        UIApplication.shared.openURL(NSURL(string: lineUrlString)! as URL)

参考

Cannot convert value of type 'String' to expected argument type 'URL'

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4