danielsteel
danielsteel

Reputation: 91

iPhone Random Number Apend URL

I'm currently using a hosted .plist file to propagate values within my application. As i would like to change these at a later date i host these online in a .plist.

However the application is caching the URL and when the contents changes the values are not updating within the application.

So i woud like to append the URL with a random number / string to ensure the most recent .plist is downloaded each time.

Any best practise advise on how to do this?

.plist parse code :

-(void)loadProducts {



NSArray *dict = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:@"https://exampleurl.com/Products.plist"]];


for (NSDictionary* productDictionary in dict) {
    ProductItem* productItem = [[ProductItem alloc] init];

Any help on this would be great!

Thanks

Upvotes: 0

Views: 102

Answers (1)

Anoop Vaidya
Anoop Vaidya

Reputation: 46563

You can use this following method to get a random text with spedified length, and them use this to append in your URL.

-(NSString *)randomText:(NSInteger)length {
    NSString *letters @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    NSMutableString *string = [NSMutableString stringWithCapacity: len];
    for (NSInteger i=0; i<length; i++) {
         [string appendFormat: @"%c", [letters characterAtIndex:arc4random()%letters.length]];
    }
    return string;
}

Upvotes: 1

Related Questions