The author | shenglan notices jas (haze away)

Edit | orange

New retail product | alibaba tao technology

Apple showed off the new iOS14 at its just-concluded online WWDC 2020 event. IOS14 adaptation, a very important part of the focus on user privacy and security.

In iOS13 and before, when users first accessed an app, they were asked to open up a lot of permissions, like albums, location, contacts, and the fact that the app might only need one feature to select an image, but they were asked to open up the entire photo library, which really didn’t make sense. For albums, the concept of “LimitedPhotos Library” has been introduced in iOS14. Users can grant apps access to some of their photos. For apps, only the photos that users choose to let apps access are available, which shows Apple’s respect for users’ privacy. This is only part of the iOS14, you can see a lot of similar measures to protect user privacy, we also need to upgrade adaptation.

Recently in the research of iOS14 adaptation scheme, this article mainly share iOS14 for privacy authorization changes and some adaptation scheme, welcome to add corrections.

Adaptation point

Photo album

IOS14 has added the “Limited Photo Library Access” mode and the Select Photo option in the authorization popover. Users can select some photos for the App to read when the App requests to call the album. From the App’s point of view, these are the only photos in your album, and the App doesn’t know about the existence of other photos.

IOS14 when the user selects the “PHAuthorizationStatusLimited”, if not fit, is likely to trigger in the photo album features are pop-up window asking the user whether to need to modify the photos.

For this case can pass on the Info. Set the value of “PHPhotoLibraryPreventAutomaticLimitedAccessAlert” to YES in the plist to stop the play repeatedly pop-up window, And you can use the following API to actively control when the PHPickerViewController pops up for photo selection.

[[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:self];
Copy the code

PHPicker is officially recommended in iOS14 to replace the original API for image selection. The PHPicker is a separate process that is displayed at the top level of the view and cannot be captured or accessed directly within the application.

1, UIImagePickerController – > PHPickerViewController, UIImagePickerViewController functional limitations, can only choose one picture each time, will gradually abandoned.

2, PHPicker support multiple selection, support search, support by image, video, livePhotos, etc.

New API and migration demo:

@interface ViewController () <PHPickerViewControllerDelegate> @property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (nonatomic, strong) NSArray<NSItemProvider *> *itemProviders; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (IBAction)button (id) Sender {// The following API is iOS14 only PHPickerConfiguration *configuration = [[PHPickerConfiguration alloc] init]; configuration.filter = [PHPickerFilter videosFilter]; / / query can be configured user photo album file types, supports three configuration. SelectionLimit = 0; // The default value is 1. If the value is 0, multiple options are available. PHPickerViewController *picker = [[PHPickerViewController alloc] initWithConfiguration:configuration]; picker.delegate = self; / / picker vc in selected after the picture need to manually in the callback dismiss [self presentViewController: picker animated: YES completion: ^ {}]. }#pragma mark - Delegate
  
  - (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results {
      [picker dismissViewControllerAnimated:YES completion:nil];
      if(! results || ! results.count) {return;
      }
      NSItemProvider *itemProvider = results.firstObject.itemProvider;
      if ([itemProvider canLoadObjectOfClass:UIImage.class]) {
          __weak typeof(self) weakSelf = self;
          [itemProvider loadObjectOfClass:UIImage.class completionHandler:^(__kindof id<NSItemProviderReading>  _Nullable object, NSError * _Nullable error) {
              if([object isKindOfClass:UIImage.class]) { __strong typeof(self) strongSelf = weakSelf; dispatch_async(dispatch_get_main_queue(), ^{ strongSelf.imageView.image = (UIImage *)object; }); }}]; }}Copy the code

Note that in Limit Photo mode, AssetsLibrary will fail to access albums; In writeOnly mode, the AssetLibrary also has display issues. We recommend that those of you who are still using AssetsLibrary migrate to the new API as soon as possible.

Authorization related: The old API is discarded. Add the PHAccessLevel parameter. If using the API to obtain permission before state, will return to PHAuthorizationStatusAuthorized PHAuthorizationStatusLimited condition

Typedef NS_ENUM(NSInteger, PHAccessLevel) {PHAccessLevelAddOnly = 1, PHAccessLevelReadWrite = 2, // Allow access to photos, LimitedLevel must bereadWrite} API_AVAILABLE(MacOS (10.16), ios(14), tVOs (14)); // Query permission PHAccessLevel level = PHAccessLevelReadWrite; PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatusForAccessLevel:level]; switch (status) {case PHAuthorizationStatusLimited:
          NSLog(@"limited");
          break;
      case PHAuthorizationStatusDenied:
          NSLog(@"denied");
          break;
      case PHAuthorizationStatusAuthorized:
          NSLog(@"authorized");
          break;
      default:
          break; } // Request permission with limited at accessLevelreadShall come into force upon the AndWrite [PHPhotoLibrary requestAuthorizationForAccessLevel: level handler: ^ (PHAuthorizationStatus status) {switch (status) {case PHAuthorizationStatusLimited:
          NSLog(@"limited");
          break;
      case PHAuthorizationStatusDenied:
          NSLog(@"denied");
          break;
      case PHAuthorizationStatusAuthorized:
          NSLog(@"authorized");
          break;
      default:
          break; }}];Copy the code

positioning

In iOS13 and before, when an App requests a user’s location authorization, it follows the following pattern: once the user agrees that the App can obtain location information, the current App can obtain the user’s precise location.

The general location option for new users in iOS14 is available to users because most apps don’t actually need to get the most accurate location information from user to user. The switch for Precise is selected by default in iOS14. This switch allows users to make changes. When set to On, the map shows the exact location. When switched to Off, the user’s approximate location is displayed.

For apps that are not highly sensitive to the user’s location, this seems to have no effect, but it is very important for App adaptation that strongly relies on accurate location. Precise location can be turned on by users in “privacy Settings,” but it is possible that users would rather not use the app than turn it on. At this point, iOS14 has two new methods in CLLocationManager that can be used to request users to temporarily enable a precise location.

Use way also is very simple, need to first in the Info. That is configured in the plist “NSLocationTemporaryUsageDescriptionDictionary” need to be configured in the dictionary of key and value shows that using the position, and specific description.

In this case, the Key is a “purposeKey” being used to get access to the user, and it ends up being displayed to the user in the picture on the left, and it is purposefully closed when the App is being used.

For geographical location is not sensitive to the App, iOS14 also can pass on the info directly. Add NSLocationDefaultAccuracyReduced plist to true default request about location.

After setting this, even if the user wants to enable precise location permission for the App, it cannot be enabled.

You can also use the API directly to set different positioning accuracy according to different requirements.

It is important to note that Beacon and other location-sensitive functions will be limited if the App is in Background mode without precise location authorization.

Local Network

IOS14 when the App wants to use Bonjour service or access local area network, use mDNS service, etc., all need authorization, developers need to describe in detail in info.plist which service is used and the purpose. The following figure shows services requiring no permission application and authorization:

You can also view and modify which apps are using LocalNetwork in “Privacy Settings”

If an application needs to use LocalNetwork, you need to configure two options in info.plist to describe why this permission is required and list the specific services that use LocalNetwork.

For any of the following frameworks that use Bonjour, update the description.

Wi-Fi Address

In iOS8 to iOS13, when users switch between different networks and access, MAC addresses will not change, which enables network operators to match users and collect user information through MAC addresses to generate complete user information. IOS14 provides Wifi encryption service, and the MAC address is different for each Wifi access. The MAC address is updated every 24 hours. Check whether there are services that use the user’s network MAC address.

The following figure shows the MAC address of the user in iOS13 and before

The following figure shows the MAC address changes when users access wi-fi in iOS14

In addition, users can choose whether to enable private Wi-Fi Address

clipboard

In iOS14, reading data from the user’s clipboard will prompt you.

The reason for the pop-up prompt is to access user data using UIPasteboard. If you access the following data, a toast prompt will pop up.

Compatibility solution: If the application access clipboard is only used to determine whether the URL format, iOS14 has two new apis to avoid this prompt. If the application wants to access the clipboard data directly, it may not be able to circumvent this prompt for the time being. Two UIPasteboardDetectionPattern iOS14 added.

The two apis above can be used to circumvent the hint, but only to determine if there is a URL in the clipboard, and do not really access clipboard data, nor do they get real clipboard data. The following two apis get specific URL information, but trigger clipboard prompts. And actually when the user clipboard contains multiple urls only the first one will be returned.

Use the sample

NSSet *patterns = [[NSSet alloc] initWithObjects:UIPasteboardDetectionPatternProbableWebURL, nil];
[[UIPasteboard generalPasteboard] detectPatternsForPatterns:patterns completionHandler:^(NSSet<UIPasteboardDetectionPattern> * _Nullable result, NSError * _Nullable error) {
    if(result && result.count) {// There is a URL in the clipboard}}];Copy the code

Camera and microphone

In iOS14, apps will have ICONS and green and yellow dots when using the camera and microphone, and it will show you which App is currently using this feature. We have no control over whether the prompt is displayed.

Examples of code that triggers a recording yellow dot:

AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:recorderPath settings:nil error:nil];
[recorder record];
Copy the code

Examples of code for triggering the small green dot on the camera:

AVCaptureDeviceInput *videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoCaptureDevice error:nil];
AVCaptureSession *session = [[AVCaptureSession alloc] init];
if ([session canAddInput:videoInput]) {
    [session addInput:videoInput];
}
[session startRunning];
Copy the code

IDFA

IDFA stands for Identity for Advertisers. It is used to mark users. At present, it is widely used for advertising, personalized recommendation and so on.

In iOS13 and before, the system will enable the setting of allowing tracking for users by default. We can simply obtain the user’s IDFA identifier through the code.

if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
    NSString *idfaString = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
    NSLog(@"% @", idfaString);
}
Copy the code

But in iOS14, this method of determining whether a user is allowed to be tracked has been scrapped.

In iOS14, the system disables AD tracking for users by default.

✎ for this case, we need to request user permissions. First of all need to be in the Info. That is configured in the plist “NSUserTrackingUsageDescription” and describe the copy, Then use in the framework of ATTrackingManager AppTrackingTransparency requestTrackingAuthorizationWithCompletionHandler request user permissions, Only after the user is authorized to access IDFA can the correct information be obtained.

#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>

- (void)testIDFA {
    if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
                NSString *idfaString = [[ASIdentifierManager sharedManager] advertisingIdentifier].UUIDString;
            }
        }];
    } else{// Use the original access to IDFA}}Copy the code

In cases where users refuse to authorize UserTracking, consider tapping into Apple’s SKAdNetwork framework for AD analytics. Interested students can learn more about: developer.apple.com/documentati…

Upload the AppStore

Stricter privacy checks will allow users to know what permissions the App will require before downloading it. Currently, the Apple Store requires all apps to provide a privacy policy when they hit the shelves. If a third party is introduced to collect user information and other SDKS, the purpose of such information should be explained to Apple.

conclusion

For this iOS14 privacy rights update and new attempts, reflects apple’s respect for user privacy.

From a user perspective, apple’s move will definitely increase our trust and affection for the company, which has seen us feel more and more “watched” by increasingly targeted advertising in recent years, with more ways to protect our privacy and avoid AD harassment. However, on the other hand, the restriction of IDFA may make it difficult for many free apps that rely on advertising revenue to maintain their livelihood, and may also lead to a decrease in the number of free apps. From the developer’s point of view, in addition to the positive adaptation of iOS14 privacy upgrade, also let us feel the importance of iOS14 for user privacy will undoubtedly improve the cost of obtaining user behavior information.

The biggest impact should be on the advertising industry, which will affect the current recommendation algorithm and user engagement. How to implement accurate advertising on the premise of fully respecting user privacy is a big opportunity and challenge for developers and advertisers.

The next issue, we talk about the new characteristics of the Metal, rounding | technology bring enlightenment and thinking], please continue to focus on ~

The resources

WWDC 2020 Apple Developer

Developer Documentation

Mobile Shopping client – Applets and cross-platform technology department

We are the core team supporting the cross-platform technologies of small programs, small games and Flutter. We have both breadth and depth of technology. We need talents from iOS, Android, C++, Flutter, Canvas, game engine, WebGL and so on. If you’re good at learning, this is a great opportunity to be exposed to cross-disciplinary knowledge.

If you are a technical pursuit of partners, please do not hesitate to contact me! 📮 : [email protected]