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?
答案 0 :(得分:0)
您可以在client ID
中的appDidFinishLaunching
方法中设置AppDelegate
,因为它只需要设置一次。
创建和执行API请求的代码可以放在您想用来启动付款的任何视图控制器中。
你是对的,最后一种方法应该添加到你的AppDelegate
。