Xamarin 形式的 iOS 捆绑包 ID

Jud*_*ham 15 xamarin.ios xamarin.forms

如何在 Xamarin 表单应用程序中找到 iOS 的包 ID 和包名称?我可以在 Android 清单中找到 Android 的包名,但对 iOS 一无所知。

EvZ*_*EvZ 15

捆绑标识符Info.plist在 iOS 项目根下定义。
这个文件就像AndroidManifest.xml在 Android 上一样。


Dav*_*ood 6

查看您的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>
Run Code Online (Sandbox Code Playgroud)

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

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

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

public String BundleId => NSBundle.MainBundle.BundleIdentifier;
Run Code Online (Sandbox Code Playgroud)


小智 1

使用 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;

Run Code Online (Sandbox Code Playgroud)

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