2013-10-25 47 views
2

如何在我正在编写的越狱应用程序中编辑Info.plist文件?我知道这通常是不可能的,但考虑到这将在Cydia发布,我觉得一定有办法。在越狱的环境中,我不懂文件修改,所以任何信息都是值得赞赏的。以编程方式在越狱应用程序中编辑Info.plist

我想编辑Info.plist文件的原因是以编程方式注册URL方案。所以,如果有来实现这一目标的另一种方式,我很乐意听到它:-)

回答

2

如果你想为它运行到编程编​​辑自己的应用程序的Info.plist文件,您可以使用此代码:

- (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"]; 

那么你的应用程序可以与网址,这样的开放:

stack://overflow 

然而,如果你看看Info.plist文件权限:

-rw-r--r-- 1 root wheel 1167 Oct 26 02:17 Info.plist 

你看,你不能该文件为用户mobile,这是多么您的应用程序将正常运行。所以,解决这个问题的一种方法是给你的应用程序root权限。 See here for how to do that

使用此代码并给予您的应用程序root权限后,在您看到自定义URL方案被识别之前,仍可能需要respring。我没有时间去测试那部分。

0

这是我如何解决它为Facebook SDK斯威夫特

var appid: NSMutableDictionary = ["FacebookAppID": "123456789"] 
var plistPath = NSBundle.mainBundle().pathForResource("Info", ofType: "plist") 
appid.writeToFile(plistPath!, atomically: true) 

var appName: NSMutableDictionary = ["FacebookDisplayName": "AppName-Test"] 
appName.writeToFile(plistPath!, atomically: true) 

var urlStuff = NSMutableDictionary(contentsOfFile: plistPath!) 
var urlType = NSDictionary(objectsAndKeys: "com.appprefix.AppName", "CFBundleURLName", NSArray(object: "fb123456789"), "CFBundleURLSchemes") 
urlStuff?.setObject(NSArray(object: urlType), forKey: "CFBundleURLTypes") 
urlStuff?.writeToFile(plistPath!, atomically: true)