从 iOS 应用内消息进行购买
为了让您的用户可以直接从 iOS 应用中显示的应用内消息进行购买,您可以为 Rich Media 实现开箱即用的解决方案,并添加回调以获取有关应用内购买的更多信息。
Rich Media JavaScript 实现
Anchor link to要在您的 Rich Media 中实现应用内购买,请使用简单的 JavaScript 函数调用:
pushwooshImpl.makePurchaseWithIdentifier("Premium"); // product identifier specified in your App Store product informationAppDelegate 回调方法
Anchor link to如果您需要在购买时执行回调,请按如下方式实现 PWPurchaseDelegate 协议:
- 使您项目的 AppDelegate 符合 PWPurchaseDelegate 协议:
@interface AppDelegate : PWAppDelegate <PushNotificationDelegate, PWPurchaseDelegate>- 在您的 AppDelegate 中实现 PWPurchaseDelegate 的方法:
#pragma mark - Purchase delegate methods- (void) onPWInAppPurchaseHelperPaymentComplete:(NSString*) identifier { NSLog(@“Custom purchase delegate -- payment complete for identifier: %@“, identifier);}-(void)onPWInAppPurchaseHelperProducts:(NSArray<SKProduct *>* _Nullable)products { NSLog(@“Custom purchase delegate -- retrieved list of products”);}-(void)onPWInAppPurchaseHelperPaymentFailedProductIdentifier:(NSString* _Nullable)identifier error:(NSError* _Nullable)error { NSLog(@“Custom purchase delegate -- payment failed with identifier %@ and error %@“, identifier, error.description);}可用的 PWPurchaseDelegate 方法列表
Anchor link to产品列表
Anchor link to@protocol PWPurchaseDelegate <NSObject>// Detailed information about list of products in your app-(void)onPWInAppPurchaseHelperProducts:(NSArray<SKProduct *>* _Nullable)products;@end成功交易
Anchor link to@protocol PWPurchaseDelegate <NSObject>// A successfully processed transaction<strong>-(void)onPWInAppPurchaseHelperPaymentComplete:(NSString* _Nullable)identifier;</strong>@end失败交易
Anchor link to@protocol PWPurchaseDelegate <NSObject><strong>// A failed transaction</strong>-(void)onPWInAppPurchaseHelperPaymentFailedProductIdentifier:(NSString* _Nullable)identifier error:(NSError* _Nullable)error;@end从 App Store 推广
Anchor link to@protocol PWPurchaseDelegate <NSObject>// An in-app purchase is initiated from the App Store, and the transaction continues in your app.-(void)onPWInAppPurchaseHelperCallPromotedPurchase:(NSString* _Nullable)identifier;@end恢复已完成交易失败
Anchor link to@protocol PWPurchaseDelegate <NSObject>// An error occurred while restoring transactions-(void)onPWInAppPurchaseHelperRestoreCompletedTransactionsFailed:(NSError * _Nullable)error;@end