该应用程序只有在用户订阅计划(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 @"*****"
我也提供了服务器端代码,但它似乎不起作用。数据库中似乎也没有任何记录。
我怎样才能做到这一点?