【问题标题】:Bundle id for iOS in Xamarin formsXamarin 表单中 iOS 的捆绑包 ID
【发布时间】:2018-04-11 07:27:27
【问题描述】:

如何在 Xamarin 表单应用程序中找到 iOS 的捆绑包 ID 和包名称?我能够在 Android 清单中找到 Android 的包名称,但对 iOS 没有任何线索。

【问题讨论】:

    标签: xamarin.forms xamarin.ios


    【解决方案1】:

    捆绑标识符在 iOS 项目根目录下的 Info.plist 中定义。
    此文件类似于 Android 上的 AndroidManifest.xml

    【讨论】:

    • 感谢@Evz 的回答
    • 我遵循了同样的过程
    【解决方案2】:

    查看您的 info.plist 文件。您会看到一个名为 CFBundleIdentifier 的密钥,它就在其中。

    这是一个例子:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>CFBundleDisplayName</key>
        <string>My App Name</string>
        <key>CFBundleName</key>
        <string>MyBundleName</string>
        <key>CFBundleIdentifier</key>
        <string>com.example.myappidentifier</string>
        <key>CFBundleShortVersionString</key>
        <string>0.1.0</string>
        <key>LSRequiresIPhoneOS</key>
        <true/>
        <key>MinimumOSVersion</key>
        <string>10.0</string>
        <key>UIDeviceFamily</key>
        <array>
            <integer>1</integer>
        </array>
        <key>UILaunchStoryboardName</key>
        <string>LaunchScreen</string>
        <key>UIRequiredDeviceCapabilities</key>
        <array>
            <string>armv7</string>
        </array>
        <key>UISupportedInterfaceOrientations</key>
        <array>
            <string>UIInterfaceOrientationPortrait</string>
        </array>
        <key>UISupportedInterfaceOrientations~ipad</key>
        <array>
            <string>UIInterfaceOrientationPortrait</string>
            <string>UIInterfaceOrientationPortraitUpsideDown</string>
            <string>UIInterfaceOrientationLandscapeLeft</string>
            <string>UIInterfaceOrientationLandscapeRight</string>
        </array>
        <key>XSAppIconAssets</key>
        <string>Assets.xcassets/AppIcon.appiconset</string>
        <key>CFBundleVersion</key>
        <string>47</string>
    </dict>
    </plist>
    

    其他有趣的键是CFBundleShortVersionString,其中包含您的应用的版本号(营销版本号,例如 1.0、1.1.0 等),以及 CFBundleVersion,其中包含您的内部版本号(1、2、3 等)。

    另请注意:.plist 文件是一种 XML 格式。您会注意到以字典部分开头的 &lt;dict&gt; 行。在里面你会看到一系列&lt;key&gt;*&lt;/key&gt; 行,每行后面跟着一个键的值,它可以是像字符串这样的简单类型,或者像数组甚至是另一个字典等更复杂的类型。当阅读/编辑 .plist 文件,每个键的值都在键的正下方。在此示例中,CFBundleIdentifier 的值为 com.example.myappidentifier

    如果您需要在代码中读取包 ID,可以将此属性添加到 Xamarin.Forms iOS 项目中的类中:

    public String BundleId => NSBundle.MainBundle.BundleIdentifier;
    

    【讨论】:

    • 感谢@Dave Wood 和您的回答。
    【解决方案3】:

    使用 Xamarin.Essentials:应用信息,您可以获得该信息并显示在您的应用中

    // Application Name
    var appName = AppInfo.Name;
    
    // Package Name/Application Identifier (com.microsoft.testapp)
    var packageName = AppInfo.PackageName;
    
    // Application Version (1.0.0)
    var version = AppInfo.VersionString;
    
    // Application Build Number (1)
    var build = AppInfo.BuildString;
    
    

    有关更多信息,请查看此 https://docs.microsoft.com/en-us/xamarin/essentials/app-information?context=xamarin%2Fxamarin-forms&tabs=android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 2017-02-11
      • 1970-01-01
      • 2022-01-18
      相关资源
      最近更新 更多