用于自动续订订阅的 MKStoreKit 4.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自动续订订阅不需要服务器组件。
Apple 会自动记住服务器上的订阅。
Auto-renewable subscriptions don't require server components.
Apple automatically takes care of remembering subscriptions on the server.