当我想在我的代码上使用付款方式进行集成测试时,我收到了这个错误。预期申报
when i want to integration testing with a payment method on my code i got this error. Expected declaration
当我写这段代码时,我遇到了这条消息错误说它是 "Expected declaration" 然后当我点击错误时它驱使我到 class 和 class 消息“1。在 'Home' 的声明中"
注意:class 的名称是 "Home"
import UIKit
import FirebaseAuth
import goSellSDK
class Home: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func barItem(_ sender: Any) {
do {
try Auth.auth().signOut()
// create the alert
let alert = UIAlertController(title: "", message: "Would you like to SignOut?", preferredStyle: UIAlertController.Style.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: "SignOut", style: UIAlertAction.Style.default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.destructive, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
} catch let error {
print("Error: ", error.localizedDescription)
}
}
let secretKey = SecretKey(sandbox: "YOUR_SANDBOX_SECRET_KEY", production: "YOUR_PRODUCTION_SECRET_KEY") // (format of the key: "sk_XXXXXXXXXXXXXXXXXXXXXXXX")
goSellSDK.secretKey = secretKey
}
这可能有帮助
据我所知,问题出在 goSellSDK.secretKey = secretKey
行。您可以在 viewDidLoad
方法中移动此行:
override func viewDidLoad() {
super.viewDidLoad()
goSellSDK.secretKey = secretKey
}
您可以在 documentation
中阅读有关 classes 和结构的更多信息
查看 goSellSDK-iOS 提供的示例应用程序,您可以看到它们在 AppDelegate 中设置了 secretKey:
import class goSellSDK.GoSellSDK //or you can `import goSellSDK`
import class goSellSDK.SecretKey
import UIKit
@UIApplicationMain
internal class AppDelegate: UIResponder, UIApplicationDelegate {
internal var window: UIWindow?
internal func applicationDidFinishLaunching(_ application: UIApplication) {
GoSellSDK.secretKey = SecretKey(sandbox: "YOUR_SANDBOX_SECRET_KEY", production: "YOUR_PRODUCTION_SECRET_KEY")
}
}
所以我会以同样的方式向你推荐。您可以在此处找到此示例文件:AppDelegate.swift
如果您在 AppDelegate.swift
中设置密钥有问题,我可以为您提供新版本 Home
class:
import UIKit
import FirebaseAuth
import goSellSDK
class Home: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
GoSellSDK.secretKey = SecretKey(sandbox: "YOUR_SANDBOX_SECRET_KEY", production: "YOUR_PRODUCTION_SECRET_KEY")
}
@IBAction func barItem(_ sender: Any) {
do {
try Auth.auth().signOut()
// create the alert
let alert = UIAlertController(title: "", message: "Would you like to SignOut?", preferredStyle: UIAlertController.Style.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: "SignOut", style: UIAlertAction.Style.default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.destructive, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
} catch let error {
print("Error: ", error.localizedDescription)
}
}
}
注意你需要使用GoSellSDK
,而不是goSellSDK
(它应该以大写G
字母开头)
当我写这段代码时,我遇到了这条消息错误说它是 "Expected declaration" 然后当我点击错误时它驱使我到 class 和 class 消息“1。在 'Home' 的声明中"
注意:class 的名称是 "Home"
import UIKit
import FirebaseAuth
import goSellSDK
class Home: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func barItem(_ sender: Any) {
do {
try Auth.auth().signOut()
// create the alert
let alert = UIAlertController(title: "", message: "Would you like to SignOut?", preferredStyle: UIAlertController.Style.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: "SignOut", style: UIAlertAction.Style.default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.destructive, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
} catch let error {
print("Error: ", error.localizedDescription)
}
}
let secretKey = SecretKey(sandbox: "YOUR_SANDBOX_SECRET_KEY", production: "YOUR_PRODUCTION_SECRET_KEY") // (format of the key: "sk_XXXXXXXXXXXXXXXXXXXXXXXX")
goSellSDK.secretKey = secretKey
}
这可能有帮助
据我所知,问题出在 goSellSDK.secretKey = secretKey
行。您可以在 viewDidLoad
方法中移动此行:
override func viewDidLoad() {
super.viewDidLoad()
goSellSDK.secretKey = secretKey
}
您可以在 documentation
中阅读有关 classes 和结构的更多信息查看 goSellSDK-iOS 提供的示例应用程序,您可以看到它们在 AppDelegate 中设置了 secretKey:
import class goSellSDK.GoSellSDK //or you can `import goSellSDK`
import class goSellSDK.SecretKey
import UIKit
@UIApplicationMain
internal class AppDelegate: UIResponder, UIApplicationDelegate {
internal var window: UIWindow?
internal func applicationDidFinishLaunching(_ application: UIApplication) {
GoSellSDK.secretKey = SecretKey(sandbox: "YOUR_SANDBOX_SECRET_KEY", production: "YOUR_PRODUCTION_SECRET_KEY")
}
}
所以我会以同样的方式向你推荐。您可以在此处找到此示例文件:AppDelegate.swift
如果您在 AppDelegate.swift
中设置密钥有问题,我可以为您提供新版本 Home
class:
import UIKit
import FirebaseAuth
import goSellSDK
class Home: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
GoSellSDK.secretKey = SecretKey(sandbox: "YOUR_SANDBOX_SECRET_KEY", production: "YOUR_PRODUCTION_SECRET_KEY")
}
@IBAction func barItem(_ sender: Any) {
do {
try Auth.auth().signOut()
// create the alert
let alert = UIAlertController(title: "", message: "Would you like to SignOut?", preferredStyle: UIAlertController.Style.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: "SignOut", style: UIAlertAction.Style.default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.destructive, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
} catch let error {
print("Error: ", error.localizedDescription)
}
}
}
注意你需要使用GoSellSDK
,而不是goSellSDK
(它应该以大写G
字母开头)