iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 10
0
Mobile Development

iOS App初心者的30天試鍊系列 第 10

Day10:今天繼續來談一下如何使用 iOS 12 SDK--Part2

  • 分享至 

  • twitterImage
  •  

今天再來把iOS 12 SDK下半段講完,我們再寫程式時如果遇到以下五個功能,我們可以

直接CALL SDK來完成

播影片: AVKit,AVPlayerViewController

網頁: SafariServices,SFSafariViewController

時間: Foundation,Date,DateFormatter,Calendar,DateComponents,Void

App 講話: AVFoundation,AVSpeechSynthesizer,AVSpeechUtterance,AVSpeechSynthesisVoice

playground: PlaygroundSupport,PlaygroundPage,liveView,type property

用 AVPlayer 播音樂

URL 代表某個資源的位置(location of a resource),比方網頁的網址,或是 App 裡檔案的路徑。

import AVFoundation
let url = URL(string: "https://music.apple.com/tw/album/說好不哭-single/1480229674?app=music&ign-itsct=330&ign-itscg=10000")
let player = AVPlayer(url: url!)
player.play()

利用 SFSafariViewController 顯示網頁

import SafariServices
import PlaygroundSupport
let url = URL(string: "https://www.apple.com/tw/iphone/")
let controller = SFSafariViewController(url: url!)
PlaygroundPage.current.liveView = controller

列印時間

import Foundation
var time = Date()
print(time)
time.addTimeInterval(10)
print(time)

利用 Date() 得到現在的時間。在程式裡Date型別代表時間,由於 Date 是在 Foundation 裡定義,所以須 import Foundation。

time.addTimeInterval(10)

在 Date 資料上增加秒數,Date資料的時間是2019/9/17 21:30:10,addTimeInterval(10) 後將變成 2019/9/17 21:30:20。


上一篇
Day9:今天來談一下如何使用 iOS 12 SDK--Part1
下一篇
Day11:今天來談一下使用Swift時變數及常數會遇到的Optional問題
系列文
iOS App初心者的30天試鍊31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言