ios - 仅为 AppDelegate.m iOS 中的首次启动设置特定方向
问题描述
我将这个库用于我的 react native 项目:
react-native-orientation-locker
我想要实现的是在除一个屏幕之外的所有屏幕上锁定方向为纵向。这个库工作正常,除非用户在横向模式下关闭应用程序,然后尝试在横向模式下打开它。应用程序在很短的时间内以横向打开,然后旋转为纵向。但我不想看到这一点,相反,我想在应用启动时以纵向模式打开应用。
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
/*if (the app has just been launched) {
return UIInterfaceOrientationMaskPortrait;
}*/
// else, use the library to manage and set orientation
return [Orientation getOrientation];
}
我不知道如何检查第一次启动以及在上面的 if 语句中放入什么
解决方案
您可以简单地检查 UserDefaults 中的某些条目,如果它不包含您提供的对象,则它首先启动。之后,您可以将此对象放入 UserDefaults
例如
if([[NSUserDefaults standardUserDefaults] boolForKey:@"SOME_YOUR_KEY"] == nil) {
// First faunch Code
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SOME_YOUR_KEY"];
[[NSUserDefaults standardUserDefaults] synchronize];
} else {
// Not first launch
}
推荐阅读
- java - 将图像动态添加到 JLabel
- vba - 循环内条件 (VBA)
- mongodb - MongoDB:如何使用聚合在 item[n] 和 item[n+1] 之间进行计算?
- reactjs - React Native 在keyboardAvoidingView中按下按钮时使键盘解除焦点
- mule-esb - 接收正文中带有图像和附件 MULE 的 HTML 邮件时为空有效负载
- mysql - MYSQL:返回 AES 加密数据返回 NULL
- r - 如何从 POSIXct 变量创建昼夜因子
- gulp - 插件/预设文件不允许导出对象,只能导出功能。在 [...]/babel-preset-es2015/lib/index.js
- python-3.x - 在组内的 Python 中创建新列
- php - PHP/Composer 包含和路径处理