LoginSignup
20
19

More than 5 years have passed since last update.

【Swiftで】Social.frameworkを使ったTwitter投稿画面【初心者でもできる】

Posted at

iOSアプリ使っているとよく見るあの画面の作り方です。
kobito.1417343105.200291.png
↑あの画面

やったことなかったけどこんなに簡単だとは思わなかったのでご紹介。

手順

①フレームワークのインポート

スクリーンショット_2014-11-30_19.26.14.png
+をクリックして「Social.framework」を選択して追加

②フレームワークのインポート

ViewController.swift
import UIKit
import Social //この行を追加

③投稿画面を表示するコードを書く

ViewController.swift
//投稿画面を作る
let twitterPostView:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)!

self.presentViewController(twitterPostView, animated: true, completion: nil)

これで表示はされます。
最初から文字を入れておきたい場合などは

twitterPostView.setInitialText(string)

としてあげればOK

ちなみに

投稿画面を作るときのforservicetypeをSLServiceTypeFaceBookとかにしてやればFacebookへの投稿画面を出すこともできます…。

20
19
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
20
19