2017-12-06 - 重拾 iOS 相关代码

2017/12/6 posted in  工作总结

WMPageController

728237-cb71fe08fe1c0ad9

CocoaPods

iOS 11:截图

  • 当调取相册的时候APP崩溃并显示标题的错误:

    • This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
  • 解决方法:

    • 在info.plst文件里添加这句
    • Privacy - Photo Library Additions Usage Description

由于官方的解释较少,又在网上查找了下其他信息:

  • iOS11以前:
    • NSPhotoLibraryUsageDescription:访问相册和存储照片到相册(读写),会出现用户授权。
  • iOS11之后:
    • NSPhotoLibraryUsageDescription:无需添加。默认开启访问相册权限(读),无需用户授权。
    • NSPhotoLibraryAddUsageDescription: 添加内容到相册(写),会出现用户授权。

工作内容:星期五上交

写一个H5和OC交互的截图功能:如下图

{184E81EB-FAD9-67E0-D880-A673780CCD8A}

UIAlertView 问题:

  • 在iOS 9.0 SDK 环境下编译上述代码时,会有下列的警告提示:

  • “‘UIAlertView’ is deprecated:first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead”

  • 意思是UIAlertView首先在iOS9中被弃用(不推荐)使用。让我们去用UIAlertController。但是运行程序,发现代码还是可以成功运行,不会出现crash。

  • 方法改为如下:

[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    //点击按钮的响应事件;
}]];
    
//弹出提示框;
[self presentViewController:alert animated:true completion:nil];

AssetsLibrary 问题:

  • AssetsLibrary/AssetsLibrary.h

  • 'ALAssetsLibrary' is deprecated: first deprecated in iOS 9.0 - Use PHPhotoLibrary from the Photos framework instead