【问题标题】:implement declaration and uiapplication delegate实现声明和uiapplication委托
【发布时间】:2017-06-21 04:43:22
【问题描述】:

iOS 开发新手,所以我对实现销售点 sdk 的这一部分有点困惑

用法

斯威夫特

进口声明:进口 SquarePointOfSaleSDK

// Replace with your app's URL scheme.
let yourCallbackURL = URL(string: "your-url-scheme://")!

// Your client ID is the same as your Square Application ID.
// Note: You only need to set your client ID once, before creating your first request.
SCCAPIRequest.setClientID("YOUR_CLIENT_ID")

do {
    // Specify the amount of money to charge.
    let money = try SCCMoney(amountCents: 100, currencyCode: "USD")

    // Create the request.
    let apiRequest =
        try SCCAPIRequest(
            callbackURL: yourCallbackURL,
            amount: money,
            userInfoString: nil,
            merchantID: nil,
            notes: "Coffee",
            customerID: nil,
            supportedTenderTypes: .all,
            clearsDefaultFees: false,
            returnAutomaticallyAfterPayment: false
        )

    // Open Point of Sale to complete the payment.
    try SCCAPIConnection.perform(apiRequest)

} catch let error as NSError {
    print(error.localizedDescription)
}

最后,实现 UIApplication 委托方法如下:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    guard let sourceApplication = options[.sourceApplication] as? String,
        sourceApplication.hasPrefix("com.squareup.square") else {
        return false
    }

    do {
        let response = try SCCAPIResponse(responseURL: url)

        if let error = response.error {
            // Handle a failed request.
            print(error.localizedDescription)
        } else {
            // Handle a successful request.
        }

    } catch let error as NSError {
        // Handle unexpected errors.
        print(error.localizedDescription)
    }

    return true
}

我有点困惑我把这些各自的代码放在哪里。我最好的猜测是 UIApplication 委托进入 AppDelegate.swift?

【问题讨论】:

    标签: square-connect


    【解决方案1】:

    您可以在AppDelegateappDidFinishLaunching 方法中设置client ID,因为它只需要设置一次。

    创建和执行 API 请求的代码可以放在您想用来启动支付的任何视图控制器中。

    你是对的,最后一个方法应该添加到你的AppDelegate

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多