var westernArabicNumeralsOnly: String {
        let pattern = UnicodeScalar("0")..."9"
        return String(unicodeScalars
            .flatMap { pattern ~= $0 ? Character($0) : nil })
    }

 

link : https://stackoverflow.com/questions/41188101/get-numbers-characters-from-a-string

 

Get numbers characters from a string

How to get numbers characters from a string? I don't want to convert in Int. var string = "string_1" var string2 = "string_20_certified" My result have to be formatted like this: newString = "1"

stackoverflow.com

 

cocoapods 에서 

Google Admob 으로 인해 오류 발생시


(firebase에서 admob 연결 안했을 경우..)

firebase와 admob 연결 후


GoogleService-info.plist 파일 다운로드.


info.plist 에

<key>GADIsAdManagerApp</key>

<true/>

 추가


'Development > iPhone' 카테고리의 다른 글

Find numbers in string in swift  (0) 2019.07.02
IAP Receipt validation function  (0) 2018.08.07
ios https 연결시 1200 에러 노출 테스트  (0) 2018.06.12
http request post swift4  (0) 2018.05.29

func checkReceiptInfo(completion: @escaping (Bool) -> Void) -> Void

    {

        let receiptURL = Bundle.main.appStoreReceiptURL

        let receipt = NSData(contentsOf: receiptURL!)

        let requestContents: [String: Any] = [

            "receipt-data": receipt!.base64EncodedString(options: [])

        ]

        

        let appleServer = receiptURL?.lastPathComponent == "sandboxReceipt" ? "sandbox" : "buy"

        

        let stringURL = "https://\(appleServer).itunes.apple.com/verifyReceipt"

        

        print("Loading user receipt: \(stringURL)...")

        

        Alamofire.request(stringURL, method: .post, parameters: requestContents, encoding: JSONEncoding.default)

            .responseJSON { response in

                if let value = response.result.value as? NSDictionary {

                    print(value)

                    let status = value.object(forKey: "status") as? Int ?? -1

                    print("status ==== >> \(status)")

                    if let receiptDic = value.object(forKey: "receipt") as? NSDictionary{

                        let inApp = receiptDic.object(forKey: "in_app") as? NSArray ?? NSArray()

                        print("in_app ---> \(inApp.count)")

                        if inApp.count > 0

                        {

                            completion(true)

                        }

                        else

                        {

                            completion(false)

                        }

                        return

                    }

                    

                    completion(false)

                } else {

                    print("Receiving receipt from App Store failed: \(response.result)")

                    

                    completion(false)

                }

        }

        

        

        

    }


터미널에서


nscurl --ats-diagnostics --verbose 체크url


호출 시

결과값이 나오며 

App Transport Security Settings

Exception Domains

에 등록해서 처리 할 값들이 노출됨 



wkwebview에서 http request post 호출이 되지 않기 떄문에

임의로 post용 html 을 생성 한 후 javascript를 이용해 post로 넘기는 방법으로 처리한다.




func makePostRequest(url: String, payload: Dictionary<String, Any>) {

    let jsonPayload: String

    do {

        let data = try JSONSerialization.data(

            withJSONObject: payload,

            options: JSONSerialization.WritingOptions(rawValue: 0))

        jsonPayload = String(data: data, encoding: String.Encoding.utf8)!

    } catch {

        jsonPayload = "{}"

    }

    

    webView.loadHTMLString(postMakingHTML(url: url, payload: jsonPayload), baseURL: nil)

}


    

private func postMakingHTML(url: String, payload: String) -> String {

    return "<html><head><script>function post(path,params,method){method = method || 'post';var form=document.createElement('form');form.setAttribute('method', method);form.setAttribute('action',path);for(var key in params){if(params.hasOwnProperty(key)){var hiddenField=document.createElement('input');hiddenField.setAttribute('type', 'hidden');hiddenField.setAttribute('name', key);hiddenField.setAttribute('value', params[key]);form.appendChild(hiddenField);}}document.body.appendChild(form);form.submit();}</script></head><body></body></html><script>post('\(url)',\(payload),'post');</script>"

}





출처 : https://blog.brainsandbeards.com/debugging-wkwebviews-5b122091db00


+ Recent posts