【问题标题】:Edit Info.plist programmatically in a jailbroken app在越狱应用程序中以编程方式编辑 Info.plist
【发布时间】:2013-10-25 15:16:39
【问题描述】:

如何在我正在编写的越狱应用中编辑 Info.plist 文件?我知道这通常是不可能的,但考虑到这将在 Cydia 中发布,我觉得一定有办法。我不精通越狱环境中的文件修改,因此感谢您提供任何信息。

我想编辑 Info.plist 文件的原因是为了以编程方式注册 URL 方案。因此,如果有另一种方法可以做到这一点,我很想听听 :-)

【问题讨论】:

    标签: ios jailbreak cydia


    【解决方案1】:

    如果您想在您自己的应用程序运行时以编程方式编辑其 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"];
    

    然后您的应用可以使用如下 URL 打开:

    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 方案被识别。我没有时间测试那部分。

    【讨论】:

      【解决方案2】:

      这是我在 Swift 中为 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)
      

      【讨论】:

        猜你喜欢
        • 2013-01-18
        • 1970-01-01
        • 2012-11-27
        • 2010-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-05
        相关资源
        最近更新 更多