การซื้อจากข้อความในแอป iOS
เพื่อให้ผู้ใช้ของคุณสามารถทำการซื้อได้โดยตรงจากข้อความในแอปที่แสดงในแอป iOS ของคุณ คุณสามารถใช้โซลูชันสำเร็จรูปสำหรับ Rich Medias ของคุณและเพิ่ม callbacks เพื่อรับข้อมูลเพิ่มเติมเกี่ยวกับการซื้อในแอปได้
การใช้งาน Rich Media JavaScript
Anchor link toหากต้องการใช้งานการซื้อในแอปใน Rich Medias ของคุณ ให้ใช้ การเรียกฟังก์ชัน JavaScript ง่ายๆ ดังนี้:
pushwooshImpl.makePurchaseWithIdentifier("Premium"); // ตัวระบุผลิตภัณฑ์ที่ระบุในข้อมูลผลิตภัณฑ์ App Store ของคุณ
เมธอด AppDelegate สำหรับ callbacks
Anchor link toหากคุณต้องการให้ callbacks ทำงานเมื่อมีการซื้อ ให้ใช้งาน protocol PWPurchaseDelegate ดังนี้:
1. ทำให้ AppDelegate ของโปรเจกต์ของคุณสอดคล้องกับ protocol PWPurchaseDelegate:
@interface AppDelegate : PWAppDelegate <PushNotificationDelegate, PWPurchaseDelegate>
2. ใช้งานเมธอดของ PWPurchaseDelegate ใน AppDelegate ของคุณ:
#pragma mark - Purchase delegate methods- (void) onPWInAppPurchaseHelperPaymentComplete:(NSString*) identifier { NSLog(@“Custom purchase delegate -- การชำระเงินเสร็จสมบูรณ์สำหรับตัวระบุ: %@“, identifier);}-(void)onPWInAppPurchaseHelperProducts:(NSArray<SKProduct *>* _Nullable)products { NSLog(@“Custom purchase delegate -- ดึงรายการผลิตภัณฑ์แล้ว”);}-(void)onPWInAppPurchaseHelperPaymentFailedProductIdentifier:(NSString* _Nullable)identifier error:(NSError* _Nullable)error { NSLog(@“Custom purchase delegate -- การชำระเงินล้มเหลวสำหรับตัวระบุ %@ และข้อผิดพลาด %@“, 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 <NSObject>// ธุรกรรมที่ประมวลผลสำเร็จ<strong>-(void)onPWInAppPurchaseHelperPaymentComplete:(NSString* _Nullable)identifier;</strong>@end
ธุรกรรมที่ล้มเหลว
Anchor link to@protocol PWPurchaseDelegate <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