Frage

I am trying to add the product IDs in app purchase. But here in the following code I am adding it manually. How can I add it from a plist?

My code:

@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;
}
War es hilfreich?

Lösung

Setup your plist as an array. Then load the NSArray from the plist file. Then create the NSSet from the 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];

Andere Tipps

You can actually load plist file into NSSArray and then load NSArray items into a NSSet using setWithArray class method, which will remove duplicates from array and add the items to set. Here is the code.

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"plist"];
NSArray * contentArray = [NSArray arrayWithContentsOfFile:plistPath];
NSSet * sampleSet = [NSSet setWithArray:contentArray];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top