InApp购买奇怪的数组安排

时间:2013-02-24 19:01:14

标签: iphone ios objective-c in-app-purchase

我正在尝试inaAppPurchases并使用以下代码

     NSSet *myProductIdentifiers = [NSSet setWithObjects:
                                     @"inapppurchase.first",
                                     @"inapppurchase.second",
                                     @"inapppurchase.third",
                                     @"inapppurchase.fourth",
                                     @"inapppurchase.fifth",
                                     @"inapppurchase.sixth",
                                     nil];

        if ((self = [super initWithProductIdentifiers:myProductIdentifiers]))
        {

        }
        return self;
///////////////////////////////////    

    - (id)initWithProductIdentifiers:(NSSet *)identifiers
    {
        if ((self = [super init]))
        {
        }
        self.productIdentifiers = identifiers;

        return self;
    }

    - (void)requestProducts
    {
        self.request = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
        request.delegate = self;
        [request start];
    }

    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
    {
        self.products = response.products;
        SKProduct *product = [self.products objectAtIndex:0];
        NSLog(@"%@", product.price);
        self.request = nil;
    }

问题是,当我调用requestProducts然后调用委托函数- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response时,产品的顺序与我的NSSet值不同

我的自我产品的顺序是第五,第一,第二,第四,第六和第三。 这是为什么? 为什么它没有正确的顺序?

1 个答案:

答案 0 :(得分:1)

与数组不同,NSSet不会按特定顺序保留对象。实际上,objectAtIndex不适用于NSSet。为了查看NSSet中的对象,您可以使用其中一个属性,例如anyObject,它随机返回集合中的对象,或allObjects,它返回一个{集合中所有对象的{1}},在返回的数组中随机排序。 NSArray可能正在访问SKProductsRequest,然后枚举数组中的每个对象以确定它是否是有效的产品。

一旦您返回随机订购的有效产品集,只需将该集合与具有正确订购的产品的数组进行比较即可。您可以在保留产品订单的同时识别任何无效产品。