I was working on this today and I encountered more strange problems:
Even though the chekReceipt() Swift function returns a String (-> String), the MyAppTransaction class method in the automatically generated name-Swift.h file is defined as (void). This won’t work because if the verificationResult is either .unverified or there is an error I need to post an alert. You can only post an alert from the main thread. Calling one from the completion handler will cause a crash. I have to return a result to the main thread to create an alert. I tried to edit the name-Swift.h header to change the return type of the checkReceiptWithCompletionHandler method to string but I can’t, it’s apparently read only.
Within the scope of the completion handler you can use the status string, for example NSLog(@"status: %@", status);, but you can’t return it to the calling function. I was hoping to copy it to the calling function with something like this:
NSString* verifyWithStoreKit(void)
{
NSString* myString;
[MyAppTransaction checkReceiptWithCompletionHandler: ^(NSString * _Nonnull status)
{
myString = [[NSString string] initWithString: status];
}];
//@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
//}
return myString;
}
But Xcode won’t build instructions like this or myString is nil. What can I do?
Topic:
App & System Services
SubTopic:
StoreKit