I'm trying to create an in-app purchase in swift. In my class signature, I have the following:
class ViewController: UIViewController, UITextFieldDelegate, UIAlertViewDelegate,
SKStoreProductViewControllerDelegate, SKPaymentTransactionObserver{
However, I get an error message: type "ViewController" does not conform to protocol: SKPaymentTransactionObserver
I've read this: https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/BuildingCocoaApps/WritingSwiftClassesWithObjective-CBehavior.html and Conform to protocol in ViewController, in Swift
The SKSoreProductViewControllerDelegate works fine. What am I missing, please?
Have you implemented the required methods in your class?
paymentQueue:updatedTransactions:
and paymentQueue:updatedDownloads:
are required methods and you will get a warning if they are not implemented.
SKPaymentTransactionProtocol
has these methods:
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!)
@optional func paymentQueue(queue: SKPaymentQueue!, removedTransactions transactions: [AnyObject]!)
@optional func paymentQueue(queue: SKPaymentQueue!, restoreCompletedTransactionsFailedWithError error: NSError!)
@optional func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue!)
@optional func paymentQueue(queue: SKPaymentQueue!, updatedDownloads downloads: [AnyObject]!)
The first is a required method that your class has to implement in order to conform to the protocol. Add it to your ViewController and the error will disappear.
class ViewController: UIViewController, UITextFieldDelegate, UIAlertViewDelegate,
SKStoreProductViewControllerDelegate, SKPaymentTransactionObserver{
func paymentQueue(queue: SKPaymentQueue!, updatedTransactions transactions: [AnyObject]!){/*...*/}
/*...*/
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With