用于自动续订订阅的 MKStoreKit 4.0

发布于 2024-12-18 08:43:30 字数 2202 浏览 0 评论 0原文

该应用程序的所有内容只有在用户订阅计划(1 个月、3 个月、6 个月或一年)后才能访问。因此,最初当应用程序首次安装时,会出现一个包含购买这些方案的选项的视图。一旦用户选择了方案并进行购买,他就获得了访问权限。

我在应用程序中初始化委托:didFinishLaunchingWithOptions: 在第一个 ViewController 中,我监听 kProductFetchedNotification 通知。一旦我收到所有产品,我就会填充界面。 我还会检查订阅是否处于活动状态

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productFetchSuccesful:) name:kProductFetchedNotification object:nil];
    ...

    if([[MKStoreManager sharedManager] isSubscriptionActive:kFeatureAId]){

        [self grantAccess];
    }else if([[MKStoreManager sharedManager] isSubscriptionActive:kFeatureBId]){
    ...
    ...
}


-(void)productFetchSuccesful:(NSNotification*)notification{

    NSArray *products = (NSArray*)[[MKStoreManager sharedManager] purchasableObjectsDescription];
    NSLog(@"%@",products);
    //*****populate ui
}

填充界面后, 。与每个订阅方案关联的 UIbuttons 链接到一个 IBAction

-(IBAction)purchaseSubscription:(id)sender{
    UIButton *currentBtn = (UIButton*)sender;
    switch (currrentBtn.tag) {
        case product1Tag:
            [[MKStoreManager sharedManager] buyFeature:kFeatureAId
                                            onComplete:^(NSString* purchasedFeature)
             {
                 NSLog(@"Purchased: %@", purchasedFeature);

                 [self grantAccess];
             }
                                           onCancelled:^
             {

             }];
            break;
        case product2Tag:
            ...
            ...
            ...
    }
}

我已经设置了 MKStoreKitConfigs.h 中的值已经设置了 OWN_SERVER 和共享秘密

#define kConsumableBaseFeatureId @"com.mycompany.myapp."
#define kFeatureAId @"1month"
#define kFeatureBId @"7days"
#define kConsumableFeatureBId @"com.mycompany.myapp.005"
#define FishBasket @"FishBasket"

#define SERVER_PRODUCT_MODEL 1
#define OWN_SERVER @"http://testsite.com/demo/itunes"
#define REVIEW_ALLOWED 1

//#warning Shared Secret Missing Ignore this warning if you don't use auto-renewable subscriptions
#define kSharedSecret @"*****"

我也已经设置了服务器端代码,但它似乎不起作用。数据库中似乎也没有记录任何内容。

我怎样才能做到这一点?

The app is such that all content can be accessed only once a user has subscribed to a scheme (1 month, 3 months, 6 months or a year). So initially when the app is first installed a view with options to buy these schemes appears. Once a user selects a scheme and makes a purchase he is given access.

I initialize the delegate at application: didFinishLaunchingWithOptions:
In the first ViewController I listen for the kProductFetchedNotification notification. and once I receive all the products i populate the interface. I also check if a subscription is active

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productFetchSuccesful:) name:kProductFetchedNotification object:nil];
    ...

    if([[MKStoreManager sharedManager] isSubscriptionActive:kFeatureAId]){

        [self grantAccess];
    }else if([[MKStoreManager sharedManager] isSubscriptionActive:kFeatureBId]){
    ...
    ...
}


-(void)productFetchSuccesful:(NSNotification*)notification{

    NSArray *products = (NSArray*)[[MKStoreManager sharedManager] purchasableObjectsDescription];
    NSLog(@"%@",products);
    //*****populate ui
}

Once the interface is populated. The UIbuttons associated with each subscription scheme is linked to an IBAction

-(IBAction)purchaseSubscription:(id)sender{
    UIButton *currentBtn = (UIButton*)sender;
    switch (currrentBtn.tag) {
        case product1Tag:
            [[MKStoreManager sharedManager] buyFeature:kFeatureAId
                                            onComplete:^(NSString* purchasedFeature)
             {
                 NSLog(@"Purchased: %@", purchasedFeature);

                 [self grantAccess];
             }
                                           onCancelled:^
             {

             }];
            break;
        case product2Tag:
            ...
            ...
            ...
    }
}

I have set the values in the MKStoreKitConfigs.h have set OWN_SERVER and shared secret

#define kConsumableBaseFeatureId @"com.mycompany.myapp."
#define kFeatureAId @"1month"
#define kFeatureBId @"7days"
#define kConsumableFeatureBId @"com.mycompany.myapp.005"
#define FishBasket @"FishBasket"

#define SERVER_PRODUCT_MODEL 1
#define OWN_SERVER @"http://testsite.com/demo/itunes"
#define REVIEW_ALLOWED 1

//#warning Shared Secret Missing Ignore this warning if you don't use auto-renewable subscriptions
#define kSharedSecret @"*****"

I have put up the server side codes as well but it doesn't seem to be working. Nothing seems to be recorded in the database as well.

How do I get this right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘味果▽酱 2024-12-25 08:43:30

自动续订订阅不需要服务器组件。
Apple 会自动记住服务器上的订阅。

Auto-renewable subscriptions don't require server components.
Apple automatically takes care of remembering subscriptions on the server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文