Iphone 多个应用内购买-如何在购买时设置不同的ID
在我的应用程序上,我设置了两个不同的应用程序内购买ID,比方说 com.myapp.purchase1 com.myapp.purchase2 升级设置为2个不同的iBaction,每个iBaction都有一个alert.tag,用于区分产品升级。 不过,这部分工作正常 购买1=删除广告 购买2=添加更多颜色 如果我购买,购买2,它的工作-广告仍然存在。 如果我购买1,它会删除广告,并解锁颜色-这是错误的 采购2链接到此处的NSUSerDefaultsIphone 多个应用内购买-如何在购买时设置不同的ID,iphone,ios,xcode,ipad,Iphone,Ios,Xcode,Ipad,在我的应用程序上,我设置了两个不同的应用程序内购买ID,比方说 com.myapp.purchase1 com.myapp.purchase2 升级设置为2个不同的iBaction,每个iBaction都有一个alert.tag,用于区分产品升级。 不过,这部分工作正常 购买1=删除广告 购买2=添加更多颜色 如果我购买,购买2,它的工作-广告仍然存在。 如果我购买1,它会删除广告,并解锁颜色-这是错误的 采购2链接到此处的NSUSerDefaults -(void)randImage {
-(void)randImage
{
currentIndex = (currentIndex+1) % ([[NSUserDefaults standardUserDefaults] boolForKey:@"com.myapp.purchase2"] ? 32 : 16);
UIImage *myImage = [UIImage imageNamed:[NSString stringWithFormat:@"f%d.png",currentIndex +1]];
[ColorsImage setImage:myImage];
}
这是来自MKStoreManager.h的
#define kConsumableBaseFeatureId @"com.myapp.colorsapp"
#define kFeatureAId @"com.myapp.purchase1"
#define kFeatureBId @"com.myapp.purchase2"
当升级过程完成时,这就是代码,我怀疑这是问题所在,但无法思考如何修复它?我在购买后调用setBool,我猜即使在购买1时也会调用它;我怎么能只在购买2时才这么说呢
-(void) provideContent: (NSString*) productIdentifier
forReceipt:(NSData*) receiptData
{
if(ownServer != nil && SERVER_PRODUCT_MODEL)
{
// ping server and get response before serializing the product
// this is a blocking call to post receipt data to your server
// it should normally take a couple of seconds on a good 3G connection
if(![self verifyReceipt:receiptData]) return;
}
NSRange range = [productIdentifier rangeOfString:kConsumableBaseFeatureId];
NSString *countText = [productIdentifier substringFromIndex:range.location+[kConsumableBaseFeatureId length]];
int quantityPurchased = [countText intValue];
if(quantityPurchased != 0)
{
int oldCount = [[NSUserDefaults standardUserDefaults] integerForKey:productIdentifier];
oldCount += quantityPurchased;
[[NSUserDefaults standardUserDefaults] setInteger:oldCount forKey:productIdentifier];
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:productIdentifier];
}
[[NSUserDefaults standardUserDefaults] synchronize];
if([_delegate respondsToSelector:@selector(productPurchased:)])
[_delegate productPurchased:productIdentifier];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"com.myapp.purchase2"];
[[NSUserDefaults standardUserDefaults] synchronize];
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Upgrades" message:@"Successfully Purchased" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
很明显,您在
provideContent:forreceive:
函数中忘记了这两行。无论何时调用它,id为“com.myapp.purchase2”的产品都将启用。从函数中删除这些行
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"com.myapp.purchase2"];
[[NSUserDefaults standardUserDefaults] synchronize];
我想我回答你的问题已经晚了,但其他人可以试试这个 对于非消耗性产品。它支持ios 5及以上版本。它还支持ios 6托管的内容,对于ios 6以下的设备,您只需添加服务器内容url即可
喜欢编码!:) 这听起来像是一个典型的案例,忘记在IBActionHi Guenis的开关盒中添加“中断”!好的,但是如果我从MKStore函数中删除这两行,那么我还能把它们放在哪里呢?因为如果用户购买com.myapp.purchase2,则需要在购买确认时启用它们?请输入if语句以了解购买的产品
if([productIdentifier IsequalString:@“com.myapp.purchase2”])
如果此语句不正确,请不要解锁@“com.myapp.purchase2”]
的内容,因此我会在MKStoreKit文件中执行此操作,例如<代码>如果([productIdentifier IseQualtString:@“com.myapp.purchase2”]){[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@“com.myapp.purchase2”];[[NSUserDefaults standardUserDefaults]synchronize];}其他{UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@“升级”消息:@“已成功购买”代理:self-CancelButtontile:@“ok”OtherButtontiles:nil,nil];[alert show];[alert release];nope。您的providecontent函数适用于所有应用内购买,对吗?因此,如果购买了@“com.myapp.purchase2”
,则将调用此函数?那么您已经在else块中启用了它{[[NSUserDefaults standardUserDefaults]setBool:YES forKey:productIdentifier];}
为什么需要再次启用它?我想我写得有些混乱。它们是两个单独的应用程序内购买,providecontent功能最初只是设置为与com.myapp.purchase1一起使用,但是我想添加第二个产品它们是单独购买的,当一个是购买时不应该启用另一个,唯一的时间是已启用,如果两者都已购买。