21 07 2017
IOS Swift Tip
- 별도 safari 브라우저 창 뛰우기
1 2 3 4 5 6 |
import SafariServices if let url = URL(string: "https://google.co.kr") { let viewController = SFSafariViewController(url: url) present(viewController, animated: true, completion: nil) } |
- 이미지 가져오기
1 2 3 4 5 6 |
if let url = URL(string: "https://wikibook.github.io/swift3-textbook/sample.jpg") { if let data = NSData(contentsOf: url) { let image = UIImage(data: data as Data) } } |
- text 읽어오기
1 2 3 4 5 6 7 8 9 10 11 |
if let url = URL(string: "https://wikibook.github.io/swift3-textbook/test.txt") { let urlSession = URLSession.shared let task = urlSession.dataTask(with: url, completionHandler: { (data, response, erro) in if let nsstr = NSString(data: data!, encoding: String.Encoding.utf8.rawValue){ let str = String(nsstr) print("문자열=[\(str)]") } }) task.resume() } |
- 앱에서 전화걸기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
let url = NSURL(string: "tel://01012345678")! if #available(iOS 10.0, *) { UIApplication.shared.open(url as URL) } else { UIApplication.shared.openURL(url as URL) } func open(scheme: String){ if let url = URL(string: scheme) { if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: { (success) in print("open \(scheme): \(success)") }) } else { // Fallback on earlier versions let success = UIApplication.shared.openURL(url) print("open \(scheme): \(success)") } } } |
- UserDefaults 사용하기
Save: UserDefaults.standard.set(“value”, forKey: “key”)
Get : if let x = UserDefaults.standard.object(forKey: “key”) as? String - Firebase login
https://www.youtube.com/watch?v=_hHohEa0H-Q - 다양한 팁
http://g-y-e-o-m.tistory.com/ - 로그인 유지
1.http://www.kaleidosblog.com/how-to-create-a-login-screen-page-in-swift-3-authenticate-an-user-and-keep-the-session-active2.https://www.raywenderlich.com/147308/secure-ios-user-data-keychain-touch-id
http://blog.naver.com/writer0713/221040662262
SimpleCaptcha 예제 IOS cocoapods 설치