一,前面已经知道了基础的环境配置,先看登录:
(1)首先要导入SDK,然后引入头文件
import GoogleSignIn
(2)然后触发登录按钮的时候进行是否需要登录的逻辑判断,进行登录
//登录
func googleSignIn(with viewController: UIViewController) {
if isGoogleConnected {//已经登录
presenter?.presentUserInfo()
return
}
if GIDSignIn.sharedInstance().hasAuthInKeychain(){//本地缓存信息 再次授权
GIDSignIn.sharedInstance().signInSilently()
} else {// 登录
cViewController = viewController
presenter?.startActivity()
let currentScopes: NSArray = GIDSignIn.sharedInstance().scopes as NSArray
GIDSignIn.sharedInstance().scopes = currentScopes.adding(Auth.Scope)
GIDSignIn.sharedInstance().signIn()
}
}
//注销
func signOut() {
GIDSignIn.sharedInstance().signOut()
GoogleOAuth2.sharedInstance.clearToken()
userStorage.user = nil
}
(3)创建直播 creade Broadcast
准备基础数据
You must specify a value for these properties:
snippet.title
snippet.scheduledStartTime
status.privacyStatus
You can set values for these properties:
snippet.title
snippet.description
snippet.scheduledStartTime
snippet.scheduledEndTime
status.privacyStatus
contentDetails.monitorStream.enableMonitorStream
contentDetails.monitorStream.broadcastStreamDelayMs
contentDetails.enableDvr
contentDetails.enableContentEncryption
contentDetails.enableEmbed
contentDetails.recordFromStart
contentDetails.startWithSlate
contentDetails.enableClosedCaptions
let title = "Big Fish Live video" //直播名称titile
let description = "Big Fish Test broadcast video"
let startDate = Helpers.dateAfter(Date(), after: (hour: 0, minute: 2, second: 0))//2分钟后开始直播
API:
POST https://www.googleapis.com/youtube/v3/liveBroadcasts
(4) create Live Stream
You must specify a value for these properties:
snippet.title
cdn.format
cdn.ingestionType
You can set values for these properties:
snippet.title
snippet.description
cdn.format
cdn.ingestionType
contentDetails.isReusable
API:https://developers.google.com/youtube/v3/live/docs/liveStreams/list
(5) Bind live stream
参数
"id":broadcastId
"streamId":streamId
"part":"id,snippet,contentDetails,status"
"key": API_KEY in the infoplist
API:https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/bind
返回数据
(6)get Live Broadcast 获取Broadcast信息
参数:
broadcastId
API:https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list
(7)get Live Stream
"part":"id,snippet,cdn,status"
"id":liveStreamId
"key": API_KEY in the infoplist
(lldb) po liveStream
▿ LiveStreamModel
- kind : "youtube#liveStream"
- etag : "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/iGgvEjOajAPRhRhyED1WrjYZZZs\""
- id : "R0RSppD9pRo-RgkQNmNoqg1533956508322798"
▿ snipped : Snipped
- publishedAt : "2018-08-11T03:01:48.000Z"
- channelId : "UCR0RSppD9pRo-RgkQNmNoqg"
- title : "Live video"
- description : "Test broadcast video"
- isDefaultStream : false
▿ cdn : CDN
- format : "720p_hfr"
- ingestionType : "rtmp"
▿ ingestionInfo : IngestionInfo
- streamName : "rwz9-dkxq-3v84-8bv3"
- ingestionAddress : "rtmp://a.rtmp.youtube.com/live2"
- backupIngestionAddress : "rtmp://b.rtmp.youtube.com/live2?backup=1"
- resolution : "720p"
- frameRate : "60fps"
▿ status : Status
- streamStatus : "inactive"
▿ healthStatus : HealthStatus
- status : "noData"
最终 我们往获取到的地址推流即可
let streamUrl = "\(streamURL)/\(streamName)"
下一章写IOS 的rtmp推流
demo