iOS 自动续费订阅 Receipt 长度 - Objective-C 代码示例
"iOS 自动续费订阅 Receipt 长度 - Objective-C 代码示例" "在 iOS 开发中,使用 StoreKit 框架处理自动续费订阅项目时,返回的购买凭证 receipt 是一个 Base64 编码的字符串。在 Objective-C 代码中,可以通过以下方式获取购买凭证 receipt 的正常长度:" "objective-c\n// 导入 StoreKit 框架\n#import \"<StoreKit/StoreKit.h>\"\n\n// 获取购买凭证 receipt\n- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {\n for (SKPaymentTransaction *transaction in transactions) {\n if (transaction.transactionState == SKPaymentTransactionStatePurchased) {\n // 获取购买凭证 receipt\n NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];\n NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];\n NSString *receiptString = [receiptData base64EncodedStringWithOptions:0];\n \n // 打印购买凭证 receipt 的长度\n NSLog(@"Receipt length: %lu", (unsigned long)[receiptString length]);\n }\n }\n}\n" "在上述代码中,我们通过 appStoreReceiptURL 方法获取到应用的购买凭证文件 URL,然后读取该文件的数据,并将其转换为 Base64 编码的字符串。最后,通过 length 方法获取到购买凭证 receipt 的长度,并将其打印出来。" "请注意,以上代码需要在遵循 SKPaymentTransactionObserver 协议的类中实现 paymentQueue:updatedTransactions: 方法,并将其设置为 SKPaymentQueue 的观察者。"
原文地址: https://www.cveoy.top/t/topic/p281 著作权归作者所有。请勿转载和采集!