ข้ามไปยังเนื้อหา

การซื้อจากข้อความในแอป iOS

เพื่อให้ผู้ใช้ของคุณสามารถทำการซื้อได้โดยตรงจากข้อความในแอปที่แสดงในแอป iOS ของคุณ คุณสามารถใช้งานโซลูชันสำเร็จรูปสำหรับ Rich Media ของคุณและเพิ่ม callbacks เพื่อรับข้อมูลเพิ่มเติมเกี่ยวกับการซื้อในแอป

การใช้งาน JavaScript ของ Rich Media

Anchor link to

ในการใช้งานการซื้อในแอปใน Rich Media ของคุณ ให้ใช้ การเรียกฟังก์ชัน JavaScript แบบง่าย:

pushwooshImpl.makePurchaseWithIdentifier("Premium"); // product identifier specified in your App Store product information

เมธอด AppDelegate สำหรับ callbacks

Anchor link to

หากคุณต้องการให้ callbacks ทำงานเมื่อมีการซื้อ ให้ใช้งาน โปรโตคอล PWPurchaseDelegate ดังนี้:

  1. ทำให้ AppDelegate ของโปรเจกต์ของคุณเป็นไปตามโปรโตคอล PWPurchaseDelegate:
@interface AppDelegate : PWAppDelegate <PushNotificationDelegate, PWPurchaseDelegate>
  1. ใช้งานเมธอดของ PWPurchaseDelegate ใน AppDelegate ของคุณ:
#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>
// ข้อมูลโดยละเอียดเกี่ยวกับรายการผลิตภัณฑ์ในแอปของคุณ
-(void)onPWInAppPurchaseHelperProducts:(NSArray<SKProduct *>* _Nullable)products;
@end

การทำธุรกรรมสำเร็จ

Anchor link to
@protocol PWPurchaseDelegate &#x3C;NSObject>
// การทำธุรกรรมที่ประมวลผลสำเร็จ
<strong>-(void)onPWInAppPurchaseHelperPaymentComplete:(NSString* _Nullable)identifier;
</strong>
@end

การทำธุรกรรมล้มเหลว

Anchor link to
@protocol PWPurchaseDelegate &#x3C;NSObject>
<strong>// การทำธุรกรรมที่ล้มเหลว
</strong>-(void)onPWInAppPurchaseHelperPaymentFailedProductIdentifier:(NSString* _Nullable)identifier error:(NSError* _Nullable)error;
@end

โปรโมทจาก App Store

Anchor link to
@protocol PWPurchaseDelegate <NSObject>
// การซื้อในแอปเริ่มต้นจาก App Store และการทำธุรกรรมจะดำเนินต่อไปในแอปของคุณ
-(void)onPWInAppPurchaseHelperCallPromotedPurchase:(NSString* _Nullable)identifier;
@end

การกู้คืนธุรกรรมที่เสร็จสมบูรณ์ล้มเหลว

Anchor link to
@protocol PWPurchaseDelegate <NSObject>
// เกิดข้อผิดพลาดขณะกู้คืนธุรกรรม
-(void)onPWInAppPurchaseHelperRestoreCompletedTransactionsFailed:(NSError * _Nullable)error;
@end