开发者

How to hardcode CFBundleIdentifier?

what els开发者_如何转开发e can I say, how do I hardcode the CFBundleIdentifier in the app ?

Thanks


If you want to change CFBundleIdentifier during runtime, you can’t unless you write to the application bundle Info.plist. That’s bad practice because the application bundle might have been moved to a read-only volume, or had its write permissions limited by the system administrator, or digitally signed to avoid tampering. I guess Launch Services wouldn’t recognise this change instantly and the application would have to be restarted. Furthermore, it is also a reason for rejection by the Mac Apple Store.

On the other hand, if you want to detect tampering of CFBundleIdentifier, you can always read its value upon application startup, e.g. in applicationDidFinishLaunching:

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
    NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
    if (! [bundleId isEqualToString:@"com.yourcompany.yourapp"])
    {
        // Ooops, CFBundleIdentifier doesn’t match
    }
}

Depending on your requirements, you might want to obfuscate the code above, including the literal strings. However, in general, you won’t be able to stop a determined adversary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜