iOS — พอดีเทสงานบน Server ที่ใช้ Certificate Self-Sign แล้วเจอ Error kCFStreamErrorDomainSSL

Numpun
Numpun
Sep 5, 2018 · 2 min read

ถ้าเจอเคสแบบนี้มีวิธีแก้หลายแบบครับ

วิธีที่ 1)
- ไปแก้ที่ Certificate ไม่ให้ Invalid ซะ ถถถถถถ+

วิธีที่ 2)
- ถ้าใช้พวก Alamofire นี้ไม่ยากเลยไป set allow invalid certificate ให้เป็นเป็น true ซะ (แต่อย่าลืมแก้ config plist.info ด้วยนะ)

วิธีที่ 3)
- ถ้าใช้ URLSession ของ iOS SDK แบบดิบ ๆ ละทำไง

ขั้นแรกก็สร้าง URLRequset ที่เราจะยิงตามปกติเลยฮะ

ขั้นที่สองสร้าง Class Requester ขึ้นมาฮะประเด็นอยู่ตรง Delegate ตรง URL Session นะครับว่าเรา Allow ให้ตัว URLSession ยอมยิง invalid certificate domain ได้ครับ

ขั้นที่สามยิงสิรออะไร

สรุป ไปใช้ Alamofire ง่ายกว่านี้เยอะครับ 5555555+

Numpun

Numpun

iOS Developer, Vue.js I choose you. Golang Lover

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade