Chính sách về dữ liệu vị trí chính xác

Thay đổi gần đây về Các chính sách dành cho nhà xuất bản của Google đã đặt ra yêu cầu mới về việc thông báo và lấy sự đồng ý cho những nhà xuất bản chuyển dữ liệu vị trí chính xác của người dùng đến Google cho các mục đích liên quan đến quảng cáo.

Nếu chính sách này áp dụng cho bạn, thì đoạn mã dưới đây cho thấy một cách để bạn có thể thông báo cho người dùng về việc chia sẻ dữ liệu này:

Swift

func presentConsentOverlayFromViewController(_ rootViewController: UIViewController) {
  if (rootViewController == nil) {
    return;
  }

  DispatchQueue.main.async {
    let alert = UIAlertController(title: "Location data",
        message: """
            We may use your location, and share it with third parties,
            for the purposes of personalized advertising, analytics,
            and attribution.
            To learn more, visit our privacy policy at https://myapp.com/privacy.
        """,
        preferredStyle: .alert)
    let alertAction = UIAlertAction(title: "OK",
        style: .default,
        handler: { _ in
          // TODO: replace the below log statement with code that specifies how
          // you want to handle the user's acknowledgement.
          print("Got consent.")
        }
    )
    alert.addAction(alertAction)
    rootViewController.present(alert, animated: true, completion: nil)
  }
}

// To use the above function assuming you are in a view controller:
presentConsentOverlayFromViewController(self)

Objective-C

- (void)presentConsentOverlayFromViewController:(UIViewController *)rootViewController {
  if (rootViewController == nil) {
    return;
  }

  dispatch_async(dispatch_get_main_queue(), ^{
      UIAlertController *alert = [UIAlertController
          alertControllerWithTitle:@"Location data"
          message: @"We may use your location, and share it with third parties,"
              @"for the purposes of personalized advertising, analytics, and attribution."
              @"To learn more, visit our privacy policy at https://myapp.com/privacy."
          preferredStyle:UIAlertControllerStyleAlert];
      UIAlertAction *ok = [UIAlertAction
          actionWithTitle:@"OK"
          style:UIAlertActionStyleDefault
          handler:^(UIAlertAction *action) {
            [alert dismissViewControllerAnimated:YES completion:^{
            // TODO: replace the below log statement with code that specifies
            // how you want to handle the user's acknowledgement.
            NSLog(@"Got consent.");
            }];
          }];

      [alert addAction:ok];
      [rootViewController presentViewController:alert animated:YES completion:nil];
  });
}

// To use the above function assuming you are in a view controller:
[self presentConsentOverlayFromViewController:self];