美文网首页
iOS16 适配问题 剪贴板问题

iOS16 适配问题 剪贴板问题

作者: 追风少年_fc4e | 来源:发表于2022-10-08 16:38 被阅读0次

iOS16 适配问题 剪贴板问题

1.隐私权限增强,如通过 UIDevice 获取设备名称时,无法获取用户的信息,只能获取设备对应的名称。(经验证iOS16任仍可使用获取设备类型,名称,系统版本)

2.UIDevice 不再支持通过setValue()方法设置设备的方向,替换为UIWindowScenerequestGeometryUpdate()方法。

3.iOS 16 更新了UIPasteControl

影响点:每次调用UIPasteboard获取用户剪切板,都会弹出授权弹窗告知用户.目前无法阻止弹窗弹出,新的API UIPasteControl 需要用户主动点击.

 - (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (@available(iOS 16.0, *)) {

        UIPasteControlConfiguration *config = [[UIPasteControlConfiguration alloc]init];
        config.baseBackgroundColor = [UIColor orangeColor];
        config.baseForegroundColor = [UIColor greenColor];
        config.cornerStyle = UIButtonConfigurationCornerStyleCapsule;
        config.displayMode = UIPasteControlDisplayModeIconAndLabel;
        _pc = [[UIPasteControl alloc] initWithConfiguration:config];
        _pc.target = self.targetTextField;

        _pc.frame = CGRectMake(0, 0, 200, 60);
        _pc.center = self.view.center;
        NSLog(@"粘贴板%@",_pc.target);
        _pc.target = self.view;
        [self.view addSubview:_pc];
        [self.view addSubview:self.targetTextField];
    } else {
        NSString *copy = [[UIPasteboard generalPasteboard] string];
        NSLog(@"粘贴板%@",copy);
    }
    
    
}
- (UITextField *)targetTextField {
    
    if (!_targetTextField) {
        
        _targetTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, self.view.frame.size.width - 20, 30)];
        
        _targetTextField.borderStyle = UITextBorderStyleRoundedRect;
        
        [_targetTextField addTarget:self
                             action:@selector(targetTextFieldAction:)
                   forControlEvents:UIControlEventEditingChanged];
        [_targetTextField becomeFirstResponder];
    }
    
    return _targetTextField;
}

- (void)targetTextFieldAction:(UITextField *)textField {
    
    NSLog(@"粘贴值%@", textField.text);
    NSLog(@"粘贴板%@,控制器%@",_pc.target, _pc.configuration);
}
原有的UIPasteboard还是可用的,在iOS16会有个提示框,用户同意即可读取用户剪贴板(16.0.2 同开发账号下的应用&应用内主动粘贴不在弹窗)
新的UIPasteControl属性如下:
UIKIT_EXTERN API_AVAILABLE(ios(16.0)) API_UNAVAILABLE(tvos, watchos) NS_SWIFT_UI_ACTOR
@interface UIPasteControl : UIControl
@property (nonatomic, readonly) UIPasteControlConfiguration *configuration;
@property (nonatomic, nullable, weak) id<UIPasteConfigurationSupporting> target;

- (instancetype)initWithConfiguration:(UIPasteControlConfiguration  *)configuration NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)coder     NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame     NS_DESIGNATED_INITIALIZER;

and

UIKIT_EXTERN API_AVAILABLE(ios(16.0))       API_UNAVAILABLE(tvos, watchos) NS_SWIFT_NAME(UIPasteControl.Configuration) NS_SWIFT_UI_ACTOR
@interface UIPasteControlConfiguration : NSObject <NSSecureCoding>
@property (nonatomic, assign) UIPasteControlDisplayMode displayMode;
@property (nonatomic, assign) UIButtonConfigurationCornerStyle cornerStyle NS_REFINED_FOR_SWIFT;
@property (nonatomic, assign) CGFloat cornerRadius;
@property (nonatomic, nullable, strong) UIColor     *baseForegroundColor;
@property (nonatomic, nullable, strong) UIColor     *baseBackgroundColor;
@end

and

UIKIT_EXTERN API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos, watchos) NS_SWIFT_UI_ACTOR
@protocol UIPasteConfigurationSupporting <NSObject>

@property (nonatomic, copy, nullable) UIPasteConfiguration *pasteConfiguration;

@optional
- (void)pasteItemProviders:(NSArray<NSItemProvider *> *)itemProviders;
- (BOOL)canPasteItemProviders:(NSArray<NSItemProvider *> *)itemProviders;

@end
适配方法: 使用UIPasteControl 需要升级Xcode14 (Xcode14兼容的最低版本为iOS11)
截图1.png
升级iOS16 测试版描述文件:https://d-updater.i4.cn/web/mobileconfig/iOS_16_DP_Beta_Profile.mobileconfig
截图2.png
使用UIPasteboard 每次使用粘贴板会弹窗告知用户,用户授权同意后才可使用
截图3.png

注:UIScreen.main即将被废弃,建议使用(UIApplication.shared.connectedScenes.first as? UIWindowScene)?.screen

10月25更新

今天更新了iOS16.1,应用在弹过授权粘贴框后,可以在设置里面找到对应的app,点击<从其他App粘贴>,选择允许后,不再弹 粘贴授权弹窗.
WechatIMG255.jpeg
WechatIMG254.jpeg

相关文章

  • iOS16适配之剪贴板

    背景 Apple从iOS14后,增加了对剪贴板内容的隐私保护 iOS16的剪贴板弹窗。 问题 虽然用户的隐私被更好...

  • XCode14 & iOS16 适配问题汇总

    1、不升级电脑系统与 Xcode,调试iOS 16 1、下载iOS16 Support文件[https://git...

  • XCode14 & iOS16 适配问题汇总

    Xcode 14 beta 6下载[https://developer.apple.com/services-ac...

  • iOS16适配:APP切换横竖屏问题

    iOS16之前切换横竖屏使用的是UIDevice的setValue:forKey:方法进行切换。但在iOS16后不...

  • iOS16问题

    1、升级到iOS16的小伙伴会发现一个问题CPU直接100%,啥也没干啊 经过挨个测试发现是导航栏根据title初...

  • XCode14 & iOS16 适配遇到的问题

    1、不升级电脑系统与 Xcode,调试iOS 16 1、下载iOS16 Support文件[https://git...

  • iOS16 xcode14 更新问题

    更新xcode14, iOS16, 编译旧项目出现下面问题, 找不到方法闪退. 问题描述<_UINavigatio...

  • iOS 16 闪退问题

    更新完iOS16之后编译旧项目出现以下问题 /* Exception NSException * "[<_...

  • iOS16适配

    开启开发者模式 iOS升级后手机默认是未打开开发者模式的,这时候会出现如下问题: Xcode 14连接真机时,发现...

  • iOS16适配

    Q1: A:iOS16中,将无法再通过_statusBarWindow获取到状态栏window,注释或切换其他方式...

网友评论

      本文标题:iOS16 适配问题 剪贴板问题

      本文链接:https://www.haomeiwen.com/subject/ykogartx.html