在越狱应用中以编程方式编辑Info.plist
如何在正在编写的越狱应用程序中编辑Info.plist文件?我知道这通常是不可能的,但是鉴于此事实将在Cydia中发布,我觉得一定有办法。我不了解越狱环境中的文件修改,因此不胜感激。
How can I edit the Info.plist file in a jailbroken app I'm writing? I know it's not normally possible but given the fact that this will be released in Cydia, I feel like there must be a way. I'm not savvy on file modifications in a jailbroken environment so any info is appreciated.
我要编辑Info.plist文件的原因是要以编程方式注册URL方案。因此,如果有另一种方法可以做到这一点,我很想听听它:-)
The reason I want to edit the Info.plist file is to register for a URL scheme programmatically. So if there's an alternative way to accomplish that, I'd love to hear it :-)
如果要通过编程方式在运行时编辑自己的应用程序的Info.plist文件,您可以使用以下代码:
If you want to programmatically edit your own app's Info.plist file as it runs, you can use this code:
- (BOOL) registerForScheme: (NSString*) scheme {
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Info"
ofType:@"plist"];
NSMutableDictionary* plist = [NSMutableDictionary dictionaryWithContentsOfFile: plistPath];
NSDictionary* urlType = [NSDictionary dictionaryWithObjectsAndKeys:
@"com.mycompany.myscheme", @"CFBundleURLName",
[NSArray arrayWithObject: scheme], @"CFBundleURLSchemes",
nil];
[plist setObject: [NSArray arrayWithObject: urlType] forKey: @"CFBundleURLTypes"];
return [plist writeToFile: plistPath atomically: YES];
}
,如果您这样称呼它:
BOOL succeeded = [self registerForScheme: @"stack"];
然后可以使用以下URL打开您的应用程序:
then your app can be open with URLs like this:
stack://overflow
但是,如果您查看Info.plist文件的权限:
However, if you look at the Info.plist file permissions:
-rw-r--r-- 1 root wheel 1167 Oct 26 02:17 Info.plist
您看到自己不能以用户 mobile
的身份向该文件写入,这就是您的应用正常运行的方式。因此,解决此问题的一种方法是为您的应用授予root特权。 有关如何操作的信息,请参见此处。
You see that you cannot write to that file as user mobile
, which is how your app will run normally. So, one way to get around this is to give your app root privileges. See here for how to do that.
使用后此代码,并赋予您的应用root特权,在您看到自定义URL方案之前,仍然有必要 respring 。我没有时间测试那部分。
After you use this code, and give your app root privileges, it still might be necessary to respring before you see your custom URL scheme recognized. I didn't have time to test that part.