使用订阅内购页

订阅内购页管理购买流程

在使用内购页的类文件中添加:

import DingYue_iOS_SDK
@import DingYue_iOS_SDK;

显示订阅内购页

在要显示内购页的方法中添加:

//自定义默认内购项
let defaultProuct1 = Subscription(type: "SUBSCRIPTION", name: "Week", platformProductId: "testWeek", price: "7.99", currencyCode: "USD", countryCode: "US")//必传字段
let defaultProuct2 = Subscription(type: "SUBSCRIPTION", name: "Year", platformProductId: "testYear", appleSubscriptionGroupId: nil, description: "default product item", period: "Year", price: "49.99", currencyCode: "USD", countryCode: "US", priceTier: nil, gracePeriod: nil, icon: nil, renewPriceChange: nil)
DYMobileSDK.showVisualPaywall(products: [defaultProuct1, defaultProuct2], rootController: self) { receipt, purchasedResult, error in
    if error == nil {
       //购买成功
    }
}

默认内购项不是必传项。

Subscription *defaultProduct = [[Subscription alloc] initWithType:@"SUBSCRIPTION" name:@"WEEK" platformProductId:@"testWeek" subscriptionDescription:@"test" period:@"week" price:@"7.99" currencyCode:@"USD" countryCode:@"US"];
[DYMobileSDK showVisualPaywallWithProducts:@[defaultProduct] rootController:self completion:^(NSString * receipt, NSArray<NSDictionary<NSString *,id> *> * purchasedInfo, DYMError * error) {
    if (error == nil) {
    }
}];

默认内购项不是必传项。

订阅内购页上的代理方法

实现 DYMPayWallActionDelegate 中的代理方法(可选):

extension UIViewController:DYMPayWallActionDelegate {
    //使用协议
    public func clickTermsAction(baseViewController: UIViewController) {
        //do some customed thing
        let vc = LBWebViewController.init()
        vc.url = "https://www.caretiveapp.com/tou/....../"
        vc.title = "Terms of Service"
        let nav = UINavigationController.init(rootViewController: vc)
        nav.modalPresentationStyle = .fullScreen
        baseViewController.present(nav, animated: true)
    }

    //隐私政策
    public func clickPrivacyAction(baseViewController: UIViewController) {
        let vc = LBWebViewController.init()
        vc.url = "https://www.caretiveapp.com/pp/....../"
        vc.title = "Privacy Policy"
        let nav = UINavigationController.init(rootViewController: vc)
        nav.modalPresentationStyle = .fullScreen
        baseViewController.present(nav, animated: true)
    }
    //点击内购页上的关闭按钮
    func clickCloseButton(baseViewController: UIViewController) {
        //to do something you want to do 
    }
    //内购页显示
    func payWallDidAppear(baseViewController: UIViewController) {
        //to do something you want to do 
    }
    //内购页消失
    func payWallDidDisappear(baseViewController: UIViewController) {
        //to do something you want to do 
    }
}
@interface ViewController ()<DYMPayWallActionDelegate>

@end
@implementation ViewController
#pragma mark - DYMPayWallActionDelegate
//使用协议
-(void)clickTermsActionWithBaseViewController:(UIViewController *)baseViewController {
    LBWebViewController *vc = [[LBWebViewController alloc] init];
    vc.url = @"https://www.caretiveapp.com/tou/....../";
    vc.title = @"Terms of Service";
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [baseViewController presentViewController:nav animated:YES completion:nil];
}

//隐私政策
-(void)clickPrivacyActionWithBaseViewController:(UIViewController *)baseViewController {
    LBWebViewController *vc = [[LBWebViewController alloc] init];
    vc.url = @"https://www.caretiveapp.com/pp/....../";
    vc.title = @"Privacy Policy";
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [baseViewController presentViewController:nav animated:YES completion:nil];
}
//点击了内购页上的关闭按钮
- (void)clickCloseButtonWithBaseViewController:(UIViewController *)baseViewController {
    //to do something you want to do 
}
//订阅内购页显示
- (void)payWallDidAppearWithBaseViewController:(UIViewController *)baseViewController {
    //to do something you want to do 
}
//订阅内购页关闭
- (void)payWallDidDisappearWithBaseViewController:(UIViewController *)baseViewController {
    //to do something you want to do 
}
@end