3

我正在尝试在应用购买中添加产品 ID。但在下面的代码中,我手动添加它。我怎样才能从一个添加它plist

我的代码:

@implementation RageIAPHelper

+ (RageIAPHelper *)sharedInstance {
    static dispatch_once_t once;
    static RageIAPHelper * sharedInstance;
    dispatch_once(&once, ^{
        NSSet * productIdentifiers = [NSSet setWithObjects:
                                      @"greatminds.assamkarttestingdays",
                                      @"greatminds.newgirlinthecity",
                                      @"greatminds.newlights",
                                      nil];
        sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];
    });
    return sharedInstance;
}
4

2 回答 2

3

您实际上可以将 plist 文件加载到 NSSArray 中,然后使用 setWithArray 类方法将 NSArray 项加载到 NSSet 中,这将从数组中删除重复项并添加要设置的项。这是代码。

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"plist"];
NSArray * contentArray = [NSArray arrayWithContentsOfFile:plistPath];
NSSet * sampleSet = [NSSet setWithArray:contentArray];
于 2013-07-18T04:40:39.943 回答
3

将您的 plist 设置为数组。然后NSArray从 plist 文件加载。然后NSSetNSArray.

// Assume you have a plist in the app bundle named "products.plist" with a root of type array
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"products" ofType:@"plist"];
NSArray *products = [NSArray arrayWithContentsOfFile:filePath];
NSSet *productIdentifiers = [NSSet setWithArray:products];
于 2013-07-18T04:36:17.757 回答