4

I append parts to a constant base URL string in my code as such:

#define BASE_URL @"https://example.com/developer/"
#define PHP_SCRIPT BASE_URL @"index.php"

such that the resulting PHP_SCRIPT refers to https://example.com/developer/index.php

I am looking for a way to insert my application's CFBundleShortVersionString into this concatenation. For example, if the CFBundleShortVersionString is 1.12 I want the final URL to be https://example.com/developer/1_12/

I know that the CFBundleShortVersionString can be accessed by

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] 

and

(__bridge NSString *)(CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey))

but I need help to concatenate it into a constant string.

4

1 回答 1

4

This should do it.

#define BASE_URL @"https://example.com/developer/"
#define PHP_SCRIPT [NSString stringWithFormat:@"%@%@/", BASE_URL, [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] stringByReplacingOccurrencesOfString:@"." withString:@"_"]]
于 2014-08-27T19:47:09.357 回答