Ios SKPaymentTransactionObserver的Appdelegate设置
我已经设置了一个Ios SKPaymentTransactionObserver的Appdelegate设置,ios,swift,Ios,Swift,我已经设置了一个PurchaseViewController,除了我意识到的多个应用商店登录是SKPaymentQueue.defaultQueue().addTransactionObserver(self),它一直工作正常。我需要将其插入Appdelegate类的didfishlaunchwithoptions函数中。当我这样做时: import UIKit import StoreKit @UIApplicationMain class AppDelegate: UIResponder,
PurchaseViewController
,除了我意识到的多个应用商店登录是SKPaymentQueue.defaultQueue().addTransactionObserver(self)
,它一直工作正常。我需要将其插入Appdelegate
类的didfishlaunchwithoptions
函数中。当我这样做时:
import UIKit
import StoreKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, SKPaymentTransactionObserver {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
UINavigationBar.appearance().barTintColor = UIColor(red: 0/255.0, green: 115/255.0, blue: 158/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
// Override point for customization after application launch.
return true
}
我获取类型Appdelegate不符合协议“SKPaymentTransactionObserver
有人能告诉我哪里出了问题吗?您已声明您的
AppDelegate
符合SKPaymentTransactionObserver
,但尚未实现
paymentQueue(uquo:updatedTransactions:)
这是一种必需的方法。这就是Xcode不高兴的原因
在AppDelegate
中执行它,Xcode将停止抱怨
请参阅。您已声明您的
AppDelegate
符合SKPaymentTransactionObserver
,但尚未实现
paymentQueue(uquo:updatedTransactions:)
这是一种必需的方法。这就是Xcode不高兴的原因
在AppDelegate
中执行它,Xcode将停止抱怨
请参阅。好的,已设法使其工作 已创建用于访问PurchaseViewController的单例
import UIKit
**let PVC_Share = PurchaseViewController.PVC_share**
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
UINavigationBar.appearance().barTintColor = UIColor(red: 0/255.0, green: 115/255.0, blue: 158/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
**PVC_Share.paymentObserver()**
// Override point for customization after application launch.
return true
}
然后在我的PurchaseViewController中创建了一个函数,以便在应用程序启动时触发transactionObserver
PurchaseViewController:
func paymentObserver()
{
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}
现在,我没有得到恼人的多弹窗登录。
谢谢你的帮助!好的,我设法让它工作了 已创建用于访问PurchaseViewController的单例
import UIKit
**let PVC_Share = PurchaseViewController.PVC_share**
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
UINavigationBar.appearance().barTintColor = UIColor(red: 0/255.0, green: 115/255.0, blue: 158/255.0, alpha: 1.0)
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.whiteColor()]
**PVC_Share.paymentObserver()**
// Override point for customization after application launch.
return true
}
然后在我的PurchaseViewController中创建了一个函数,以便在应用程序启动时触发transactionObserver
PurchaseViewController:
func paymentObserver()
{
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}
现在,我没有得到恼人的多弹窗登录。
谢谢您的帮助!可能缺少委托方法?可能缺少委托方法?是的,paymentQueue(\uuuz:updatedTransactions:)方法已在另一个viewController类中实现。您是否建议创建一个单例。这是此处可接受的过程吗?如果您不在此处实现委托方法,请从AppDelegate中删除
SKPaymentTransactionObserver
。另外,构建一些帮助器类来管理应用内购买也是明智的和委托。不必是单例的,但也不会造成任何伤害。是的,paymentQueue(\uuUx:updatedTransactions:)方法已在另一个viewController类中实现。您是否建议创建一个单例。这是此处可接受的过程吗?如果您不在此处实现委托方法,请从AppDelegate中删除SKPaymentTransactionObserver
。另外,构建一些帮助器类来管理应用内购买也是明智的和代表。不必是单身,但也不会有伤害。