Slide 48
Slide 48 text
)PNF,JU"%,
ࣗͰΞΫηαϦʔΛ࡞Δ
#!/usr/bin/swift
import Foundation
let slackURL = URL(string: "Incoming Webhook URL")
var request = URLRequest(url: slackURL!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-type")
let message = "ϥΠτ͕౮"
let postData = "{\"text\": \"\(message)\"}".data(using: .utf8)
request.httpBody = postData
let semaphore = DispatchSemaphore(value: 0)
let session = URLSession(configuration: URLSessionConfiguration.default)
let task = session.dataTask(with: request) { _, _, _ in
semaphore.signal()
}
task.resume()
semaphore.wait()