Google User Messaging Platform (UMP) SDK ابزاری برای حفظ حریم خصوصی و پیامرسانی است که به شما در مدیریت انتخابهای حریم خصوصی کمک میکند. برای اطلاعات بیشتر،درباره حریم خصوصی و پیامرسانی را ببینید.
یک نوع پیام ایجاد کنید
ایجاد پیامهای کاربری با یکی ازانواع پیام کاربر موجوددر برگه حریم خصوصی و پیامرسانی حسابAdMob. UMP SDK تلاش میکند یک پیام حفظ حریم خصوصی ایجاد شده از شناسه برنامه AdMob را در پروژه شما نمایش دهد.
برای جزئیات بیشتر،درباره حریم خصوصی و پیامرسانی را ببینید.
SDK را وارد کنید
CocoaPods (ترجیحا)
ساده ترین راه برای وارد کردن SDK به پروژه iOS استفاده از CocoaPods است. Podfile پروژه خود را باز کنید و این خط را به هدف برنامه خود اضافه کنید:
pod 'GoogleUserMessagingPlatform'
سپس دستور زیر را اجرا کنید:
pod install --repo-update
اگر با CocoaPods تازه کار هستید، برای جزئیات بیشتر در مورد نحوه ایجاد و استفاده از Podfiles به استفاده از CocoaPods مراجعه کنید.
مدیر بسته سوئیفت
UMP SDK همچنین از مدیریت بسته Swift پشتیبانی می کند. برای وارد کردن بسته سوئیفت این مراحل را دنبال کنید.
در Xcode، بسته UMP SDK Swift را با رفتن به File > Add Packages... نصب کنید.
در اعلان ظاهر شده، مخزن UMP SDK Swift Package GitHub را جستجو کنید:
https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
نسخه UMP SDK Swift Package را که می خواهید استفاده کنید انتخاب کنید. برای پروژههای جدید، توصیه میکنیم از نسخه اصلی تا بعدی استفاده کنید.
سپس Xcode وابستگی های بسته شما را برطرف می کند و آنها را در پس زمینه دانلود می کند. برای جزئیات بیشتر در مورد نحوه افزودن وابستگی های بسته، به مقاله اپل مراجعه کنید.
دانلود دستی
راه دیگر وارد کردن SDK این است که آن را به صورت دستی انجام دهید.
سپس، چارچوب را به پروژه Xcode خود بکشید و مطمئن شوید که در صورت نیاز موارد کپی را انتخاب کنید.
سپس می توانید چارچوب را در هر فایلی که نیاز دارید با استفاده از:
سریع
import UserMessagingPlatform
هدف-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
شناسه برنامه را اضافه کنید
میتوانید شناسه برنامه خود را در رابط کاربری AdMobپیدا کنید.شناسه را با قطعه کد زیر بهInfo.plist
:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>
درخواست اطلاعات رضایت
باید در هر راهاندازی برنامه، با استفاده از requestConsentInfoUpdateWithParameters:completionHandler:
درخواست بهروزرسانی اطلاعات رضایت کاربر را بدهید. این درخواست موارد زیر را بررسی می کند:
- آیا رضایت لازم است . به عنوان مثال، برای بار اول رضایت لازم است، یا تصمیم قبلی رضایت منقضی شده است.
- آیا یک نقطه ورود گزینه های حریم خصوصی مورد نیاز است یا خیر . برخی از پیامهای حریم خصوصی به برنامهها نیاز دارند که به کاربران اجازه دهند گزینههای حریم خصوصی خود را در هر زمان تغییر دهند.
در اینجا مثالی از نحوه بررسی وضعیت از طریق UIViewController
در متد viewDidLoad()
آورده شده است.
سریع
override func viewDidLoad() {
super.viewDidLoad()
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
[weak self] requestConsentError in
guard let self else { return }
if let consentError = requestConsentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
// TODO: Load and present the privacy message form.
}
}
هدف-C
- (void)viewDidLoad {
[super viewDidLoad];
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:nil
completionHandler:^(NSError *_Nullable requestConsentError) {
if (requestConsentError) {
// Consent gathering failed.
NSLog(@"Error: %@", requestConsentError.localizedDescription);
return;
}
// TODO: Load and present the privacy message form.
}];
}
در صورت نیاز فرم پیام حریم خصوصی را بارگیری و ارائه دهید
پس از دریافت بهروزترین وضعیت رضایت، باloadAndPresentIfRequiredFromViewController:completionHandler:
تماس بگیرید تا فرمهای مورد نیاز برای دریافت رضایت کاربر بارگیری شود. پس از بارگذاری، فرم ها بلافاصله ارائه می شوند.
سریع
override func viewDidLoad() {
super.viewDidLoad()
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
[weak self] requestConsentError in
guard let self else { return }
if let consentError = requestConsentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
UMPConsentForm.loadAndPresentIfRequired(from: self) {
[weak self] loadAndPresentError in
guard let self else { return }
if let consentError = loadAndPresentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
// Consent has been gathered.
}
}
}
هدف-C
- (void)viewDidLoad {
[super viewDidLoad];
__weak __typeof__(self) weakSelf = self;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:nil
completionHandler:^(NSError *_Nullable requestConsentError) {
if (requestConsentError) {
// Consent gathering failed.
NSLog(@"Error: %@", requestConsentError.localizedDescription);
return;
}
__strong __typeof__(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
completionHandler:^(NSError *loadAndPresentError) {
if (loadAndPresentError) {
// Consent gathering failed.
NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
return;
}
// Consent has been gathered.
}];
}];
}
اگر پس از انتخاب کاربر یا رد کردن فرم، نیاز به انجام هر کاری دارید، آن منطق را در completion handlerبرای فرم خود قرار دهید.
گزینه های حفظ حریم خصوصی
برخی از فرمهای پیام حریم خصوصی از نقطه ورود گزینههای حریم خصوصی ارائهشده توسط ناشر ارائه میشوند و به کاربران اجازه میدهند گزینههای حریم خصوصی خود را در هر زمان مدیریت کنند. برای کسب اطلاعات بیشتر در مورد پیامی که کاربران شما در نقطه ورودی گزینه های حریم خصوصی می بینند، بهانواع پیام کاربر موجود مراجعه کنید.
برای پیاده سازی یک نقطه ورود گزینه های حریم خصوصی، مراحل زیر را انجام دهید:
-
UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus
بررسی کنید. - اگر به نقطه ورود گزینه های حریم خصوصی نیاز است، یک عنصر رابط کاربری قابل مشاهده و قابل تعامل به برنامه خود اضافه کنید.
- فرم گزینه های حریم خصوصی را با استفاده از
presentPrivacyOptionsFormFromViewController:completionHandler:
فعال کنید.
مثال کد زیر این مراحل را نشان می دهد:
سریع
@IBOutlet weak var privacySettingsButton: UIBarButtonItem!
var isPrivacyOptionsRequired: Bool {
return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == .required
}
override func viewDidLoad() {
// ...
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
// ...
UMPConsentForm.loadAndPresentIfRequired(from: self) {
//...
// Consent has been gathered.
// Show the button if privacy options are required.
self.privacySettingsButton.isEnabled = isPrivacyOptionsRequired
}
}
// ...
}
// Present the privacy options form when a user interacts with the
// privacy settings button.
@IBAction func privacySettingsTapped(_ sender: UIBarButtonItem) {
UMPConsentForm.presentPrivacyOptionsForm(from: self) {
[weak self] formError in
guard let self, let formError else { return }
// Handle the error.
}
}
هدف-C
@interface ViewController ()
@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;
@end
- (BOOL)isPrivacyOptionsRequired {
return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
UMPPrivacyOptionsRequirementStatusRequired;
}
- (void)viewDidLoad {
// ...
__weak __typeof__(self) weakSelf = self;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable requestConsentError) {
// ...
[UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
completionHandler:^(NSError *loadAndPresentError) {
// ...
// Consent has been gathered.
// Show the button if privacy options are required.
strongSelf.privacySettingsButton.enabled = isPrivacyOptionsRequired;
}];
}];
}
// Present the privacy options form when a user interacts with your
// privacy settings button.
- (IBAction)privacySettingsTapped:(UIBarButtonItem *)sender {
[UMPConsentForm presentPrivacyOptionsFormFromViewController:self
completionHandler:^(NSError *_Nullable formError) {
if (formError) {
// Handle the error.
}
}];
}
درخواست تبلیغات
قبل از درخواست تبلیغات در برنامه خود، بررسی کنید که آیا رضایت کاربر را با استفاده از UMPConsentInformation.sharedInstance.canRequestAds
دریافت کرده اید یا خیر. هنگام جمع آوری رضایت دو مکان برای بررسی وجود دارد:
- پس از کسب رضایت در جلسه جاری.
- بلافاصله پس از تماس با
requestConsentInfoUpdateWithParameters:completionHandler:
. امکان دارد در جلسه قبل رضایت گرفته شده باشد. بهعنوان بهترین روش تأخیر، توصیه میکنیم منتظر تکمیل تماس نمانید تا بتوانید در اسرع وقت پس از راهاندازی برنامه، بارگیری تبلیغات را شروع کنید.
اگر در فرآیند جمعآوری رضایت خطایی رخ داد، همچنان باید سعی کنید تبلیغات را درخواست کنید. UMP SDK از وضعیت رضایت جلسه قبل استفاده می کند.
سریع
class ViewController: UIViewController {
// Use a boolean to initialize the Google Mobile Ads SDK and load ads once.
private var isMobileAdsStartCalled = false
override func viewDidLoad() {
super.viewDidLoad()
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
[weak self] requestConsentError in
guard let self else { return }
if let consentError = requestConsentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
UMPConsentForm.loadAndPresentIfRequired(from: self) {
[weak self] loadAndPresentError in
guard let self else { return }
if let consentError = loadAndPresentError {
// Consent gathering failed.
return print("Error: \(consentError.localizedDescription)")
}
// Consent has been gathered.
if UMPConsentInformation.sharedInstance.canRequestAds {
self.startGoogleMobileAdsSDK()
}
}
}
// Check if you can initialize the Google Mobile Ads SDK in parallel
// while checking for new consent information. Consent obtained in
// the previous session can be used to request ads.
if UMPConsentInformation.sharedInstance.canRequestAds {
startGoogleMobileAdsSDK()
}
}
private func startGoogleMobileAdsSDK() {
DispatchQueue.main.async {
guard !self.isMobileAdsStartCalled else { return }
self.isMobileAdsStartCalled = true
// Initialize the Google Mobile Ads SDK.
GADMobileAds.sharedInstance().start()
// TODO: Request an ad.
// GADInterstitialAd.load(...)
}
}
}
هدف-C
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
__weak __typeof__(self) weakSelf = self;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:nil
completionHandler:^(NSError *_Nullable requestConsentError) {
if (requestConsentError) {
// Consent gathering failed.
NSLog(@"Error: %@", requestConsentError.localizedDescription);
return;
}
__strong __typeof__(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
[UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
completionHandler:^(NSError *loadAndPresentError) {
if (loadAndPresentError) {
// Consent gathering failed.
NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
return;
}
// Consent has been gathered.
__strong __typeof__(self) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
if (UMPConsentInformation.sharedInstance.canRequestAds) {
[strongSelf startGoogleMobileAdsSDK];
}
}];
}];
// Check if you can initialize the Google Mobile Ads SDK in parallel
// while checking for new consent information. Consent obtained in
// the previous session can be used to request ads.
if (UMPConsentInformation.sharedInstance.canRequestAds) {
[self startGoogleMobileAdsSDK];
}
}
- (void)startGoogleMobileAdsSDK {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Initialize the Google Mobile Ads SDK.
[GADMobileAds.sharedInstance startWithCompletionHandler:nil];
// TODO: Request an ad.
// [GADInterstitialAd loadWithAdUnitID...];
});
}
آزمایش کردن
اگر میخواهید یکپارچهسازی برنامه خود را در حین توسعه آزمایش کنید، این مراحل را دنبال کنید تا دستگاه آزمایشی خود را به صورت برنامهنویسی ثبت کنید. قبل از انتشار برنامه، حتماً کدی را که این شناسههای دستگاه آزمایشی را تنظیم میکند حذف کنید.
- با
requestConsentInfoUpdateWithParameters:completionHandler:
تماس بگیرید. خروجی گزارش را برای پیامی شبیه به مثال زیر بررسی کنید، که شناسه دستگاه شما و نحوه افزودن آن را به عنوان یک دستگاه آزمایشی نشان می دهد:
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
شناسه دستگاه آزمایشی خود را در کلیپ بورد خود کپی کنید.
کد خود را به .
سریع
let parameters = UMPRequestParameters() let debugSettings = UMPDebugSettings() debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"] parameters.debugSettings = debugSettings // Include the UMPRequestParameters in your consent request. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate( with: parameters, completionHandler: { error in ... })
هدف-C
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init]; debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ]; parameters.debugSettings = debugSettings; // Include the UMPRequestParameters in your consent request. [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError *_Nullable error){ ... }];
جغرافی اجباری
UMP SDK راهی برای آزمایش رفتار برنامه شما ارائه میکند که گویی دستگاه در منطقه اقتصادی اروپا یا بریتانیا با استفاده از the debugGeography
property of type UMPDebugGeography
on UMPDebugSettings
قرار دارد. توجه داشته باشید که تنظیمات اشکال زدایی فقط در دستگاه های آزمایشی کار می کند.
سریع
let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
debugSettings.geography = .EEA
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
with: parameters,
completionHandler: { error in
...
})
هدف-C
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
debugSettings.geography = UMPDebugGeographyEEA;
parameters.debugSettings = debugSettings;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable error){
...
}];
وضعیت رضایت را بازنشانی کنید
در آزمایش برنامه خود با UMP SDK، ممکن است بازنشانی وضعیت SDK برای شما مفید باشد تا بتوانید اولین تجربه نصب کاربر را شبیه سازی کنید. SDK روش reset
برای انجام این کار ارائه می دهد.
سریع
UMPConsentInformation.sharedInstance.reset()
هدف-C
[UMPConsentInformation.sharedInstance reset];