ez_iap 1.0.0

ez_iap 1.0.0

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
发布最后发布2020年10月

ihowe 维护。



ez_iap 1.0.0

  • 作者
  • Howe Ho

ez_iap

一个简单的 iOS IAP 库。

开始使用

1. 在你的 Podfile 中添加以下内容

pod 'ez_iap'

2. 导入所需的头文件


#import <ez_iap/IAPApi.h>


// Declare that the IAP delegate implements the EZIAPDelegate protocol.
@interface PluginIAP : PluginBase<EZIAPDelegate>

3. 将 IAPApi 添加到您的代码中


    // if YES, IAPApi will autoverfify the receipt,  default NO;
    // Recommended use server authentication!
	[IAPApi Instance].autoVerify = YES;
	
    // set to debugMode or not, default NO;
	[IAPApi Instance].debugMode = YES;
	
	[IAPApi Instance].delegate = self;

4. 通过定义以下方法实现 EZIAPDelegate 协议以处理 IAP 流程

#pragma mark -
#pragma mark EZIAPDelegate 
- (void) payResult:(NSDictionary*)payInfo{

	/**
		payInfo = {
			productID:"xxxx",
			productIdentifier:"xxxx",     //same as ‘productID’
			billNO:"zzzz",                // A billNO you send to IAP
 			transactionIdentifier:"yyyy", // appstore transactionIdentifier
			receipt:"KKKKK",              // appstore payment receipt 
		}
	
	*/
    // If the payment is successful, the next step is to verify the order. 
    // If autoverify = true, it will be completed automatically
    [self nativeEventHandler:@"pay_success" andParams:[JSONUtil stringify:payInfo]];
}

- (void) verifyResult:(NSString*)billNO andProductID:(NSString*)productID andResult:(NSDictionary*)verfyInfo{
	// receipt verify Result 
	// Verfyinfo is the result of Apple's order, you can check the order status and paymentInfo;
    
}

- (void) productList:(NSArray*)list{
    // appleconnect payment list
    
}

- (void) IAPFailed:(NSString*)billNO andProductID:(NSString*)productID widthError:(NSError*)error{
    NSMutableDictionary *ret = [NSMutableDictionary dictionary];
    if (error){
        NSLog(@"[PluginIAP] %@ %@ error = %@",productID,billNO,error);
        NSString *desc = [error localizedDescription];
        switch (error.code) {
            case SKErrorPaymentCancelled:
            {
                desc = @"The payment has been cancelled.";
                break;
            }
            case SKErrorPaymentInvalid:
            {
                desc = @"Purchase identifier was invalid.";
                break;
            }
            case SKErrorStoreProductNotAvailable:
            {
                desc = @"Product is not available in the current storefront.";
                break;
            }
            default:
                break;
        }
        [PluginCore alert:@"Message" andMsg:desc];
        [ret setObject:desc forKey:@"msg"];
    }
    [ret setObject:billNO forKey:@"billNO"];
    [ret setObject:productID forKey:@"productID"];
    [self nativeEventHandler:@"pay_error" andParams:[JSONUtil stringify:ret]];
}

5. 开始支付

/**
 * request pay
 * @param product productIdentifier
 * @param billNO  you billNO (a string which can identify the user)
 **/
[[IAPApi Instance] buy:{productId} billNo:{billNO}];

6. 获取 App Store 中的产品列表


/**
 * Get product list of app store
 * @param productArray 产品id数组
 **/
[[IAPApi Instance] getProductList:{productArray}];

7. 验证收据


IAPApi *api = [IAPApi Instance];
        [api verifyReceipt:receiptStr andDebug:NO withResultHandler:^(NSError *error, NSDictionary *response) {
            if (error){
                [self nativeCallbackErrorHandler:callback andParams:[error localizedDescription] ];
            }else{
                [self nativeCallbackHandler:callback andParams:[JSONUtil stringify:response]];
            }
        }];
        

过瘾!

[email protected]  2020/10/26