I have an application in which I am implementing MKStorekit4 to have autorenewable purchases. I have successfully copied the code. When I am trying to call [MKStoreManager sharedManager]; on my appdelegate it will throws an error "cannot add nil observer" then it crashes.
This is my code
+ (MKStoreManager*)sharedManager
{
@synchronized(self) {
if (_sharedStoreManager == nil) {
#if TARGET_IPHONE_SIMULATOR
NSLog(@"You are running in Simulator MKStoreKit runs only on devices");
#else
_sharedStoreManager = [[self alloc] init];
_sharedStoreManager.purchasableObjects = [[NSMutableArray alloc] init];
[_sharedStoreManager requestProductData];
_sharedStoreManager.storeObserver = [[MKStoreObserver alloc] init];
[[SKPaymentQueue defaultQueue]
addTransactionObserver:_sharedStoreManager.storeObserver];
[_sharedStoreManager startVerifyingSubscriptionReceipts];
#endif
}
}
return _sharedStoreManager;
}
What am I doing wrong? Any help will be greatly appreciated.
This means that your
_sharedStoreManager.storeObserveris nil.But that’s really strange.
Try to
NSLog("Observer %@",[_sharedStoreManager.storeObserver description])after_sharedStoreManager.storeObserver = [[MKStoreObserver alloc] init];to see if it has really allocated.