I'm declaring that my app delegate conforms to the protocols
<UIApplicationDelegate, SKPaymentTransactionObserver>
in the app delegate header file (i.e. the app delegate interface).
The compiler tells me at numer开发者_如何学编程ous places in my code that:
warning: type 'id <UIApplicationDelegate>' does not conform to the 'SKPaymentTransactionObserver' protocol
What's up?
You're probably doing something like [[SKPaymentQueue defaultQueue] addTransactionObserver:[[UIApplication sharedApplication] delegate]]
. Since -[UIApplication delegate]
is declared as returning id<UIApplicationDelegate>
, the compiler has no way of knowing that the object returned will implement the SKPaymentTransactionObserver protocol. Try assigning the delegate to a variable that's statically typed as your delegate class and pass that to the method you're trying to call and the compiler should be happy.
Your ApplicationDelegate seems to be missing some of the required delegates, for example:
- (void)applicationWillResignActive:(UIApplication *)application
Check what delegate methods SKPaymentTransactionObserver
requires, and add them to your AppDelegate.m
Also, check over the SKPaymentTransactionObserver Protocol Reference
精彩评论