我正在尝试在应用购买中添加产品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;
}
答案 0 :(得分:3)
将plist设置为数组。然后从plist文件加载NSArray
。然后从NSSet
创建NSArray
。
// 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];
答案 1 :(得分:3)
您实际上可以将plist文件加载到NSSArray中,然后使用setWithArray类方法将NSArray项加载到NSSet中,这将从数组中删除重复项并添加要设置的项。这是代码。
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"plist"];
NSArray * contentArray = [NSArray arrayWithContentsOfFile:plistPath];
NSSet * sampleSet = [NSSet setWithArray:contentArray];