如何配置capacitor 打包的ios app固定竖屏展示?

注:打包ios包需要使用xcode来进行打包,Xcode 提供了为 Apple 平台开发、测试和分发 App 所需的工具,包括预测代码补全、主流编码模型加持的生成式智能功能、高级分析和调试工具,以及适用于 Apple 设备的模拟器。因此打包ios包的前提是需要一台苹果电脑。

找到/ios/App/App/Info.plist文件,并打开,如下图:

XML 复制代码
<?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>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleDisplayName</key>
        <string>traction-digital-twin-mobile-app1</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>$(MARKETING_VERSION)</string>
	<key>CFBundleVersion</key>
	<string>$(CURRENT_PROJECT_VERSION)</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<!-- iPhone仅保留竖屏(Home 键在下的正常竖屏) -->
		<string>UIInterfaceOrientationPortrait</string>
		<!-- <string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string> -->
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<!-- iPad仅保留竖屏(Home 键在下的正常竖屏) -->
		<string>UIInterfaceOrientationPortrait</string>
		<!-- iPad允许倒竖屏 -->
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<!-- <string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string> -->
	</array>
	<key>UIViewControllerBasedStatusBarAppearance</key>
	<true/>

	<!-- 通知权限描述 -->
	<key>NSLocalNotificationUsageDescription</key>
	<string>需要向您发送本地通知,提醒重要事项</string>

	<!-- 后台通知支持(可选,用于后台触发通知) -->
	<key>UIBackgroundModes</key>
	<array>
		<string>remote-notification</string>
	</array>

	<!-- iOS 10+ 通知声音配置(若使用自定义声音,需添加) -->
	<key>UILocalNotificationDefaultSoundName</key>
	<string>default</string> <!-- 使用系统默认声音,自定义声音需放入项目并指定文件名 -->
</dict>
</plist>

根据以下注释配置,将

<string>UIInterfaceOrientationLandscapeLeft</string>

<string>UIInterfaceOrientationLandscapeRight</string>

这两行注释掉, <key>UISupportedInterfaceOrientations</key> 这个是指对iPhone屏幕横竖屏的设置;**<key>UISupportedInterfaceOrientations~ipad</key>**则是指对iPad屏幕横竖屏的设置,保险起见,也把iPad的

<string>UIInterfaceOrientationLandscapeLeft</string>

<string>UIInterfaceOrientationLandscapeRight</string>这两个注释掉,然后重新运行ionic capacitor build ios进行打包安装,xcode打开项目后,建议检查一遍xcode上面的打包配置,检查步骤如图:

安装成功后的效果图:

以上是自己在项目里遇到的问题以及解决的方法,浅浅记录一下~

相关推荐
2501_9151063212 分钟前
如何查看手机使用记录:Android和iOS设备全面指南
android·ios·智能手机·小程序·uni-app·iphone·webview
小鑫同学12 分钟前
Alias Assistant:新一代 macOS Shell 别名管理解决方案
前端·前端工程化
꒰ঌ小武໒꒱12 分钟前
RuoYi-Vue 前端环境搭建与部署完整教程
前端·javascript·vue.js·nginx
名字越长技术越强30 分钟前
前端之相对路径
前端
望道同学1 小时前
PMP/信息系统项目管理师 9 张 思维导图【考试必备】
前端·后端·程序员
局i2 小时前
Vue 中 v-text 与 v-html 的区别:文本渲染与 HTML 解析的抉择
前端·javascript·vue.js
菜鸟冲锋号2 小时前
问题:增量关联(实时同步新数据) 这个场景中,如果hudi_pay 变更了一条数据,hudi_order_pay_join 结果的数据会跟着变化吗
服务器·前端·数据库
贩卖黄昏的熊2 小时前
typescript 快速入门
开发语言·前端·javascript·typescript·ecmascript·es6
拾柒SHY3 小时前
XSS-Labs靶场通关
前端·web安全·xss
前端婴幼儿3 小时前
前端主题切换效果
前端