इस गाइड में, iPhone X पर विज्ञापन सही तरीके से दिखाने के लिए, ऐप्लिकेशन को कोड करने के सबसे सही तरीकों के बारे में बताया गया है.
ज़रूरी शर्तें
- Google Mobile Ads SDK का वर्शन 7.26.0 या इसके बाद वाला वर्शन इंपोर्ट करें. इसे अलग से या Firebase के हिस्से के तौर पर इंपोर्ट किया जा सकता है.
बैनर विज्ञापन
बैनर विज्ञापनों को "सुरक्षित जगह" पर रखा जाना चाहिए, ताकि गोल किए गए कोने, सेंसर हाउसिंग, और होम इंडिकेटर की वजह से विज्ञापन दिखने में दिक्कत न हो. इस पेज पर, बैनर को सुरक्षित जगह में ऊपर या नीचे रखने के लिए, सीमाएं जोड़ने के तरीके के उदाहरण दिए गए हैं.
स्टोरीबोर्ड/इंटरफ़ेस बिल्डर
अगर आपका ऐप्लिकेशन, इंटरफ़ेस बिल्डर का इस्तेमाल करता है, तो सबसे पहले पक्का करें कि आपने सुरक्षित जगह के लेआउट गाइड चालू किए हों. इसके लिए, आपको Xcode 9+ पर काम करना होगा. साथ ही, iOS 9+ को टारगेट करना होगा.
इंटरफ़ेस बिल्डर फ़ाइल खोलें और व्यू कंट्रोलर सीन पर क्लिक करें. आपको दाईं ओर, इंटरफ़ेस बिल्डर दस्तावेज़ के विकल्प दिखेंगे. सुरक्षित जगह के लेआउट गाइड का इस्तेमाल करें पर सही का निशान लगाएं. साथ ही, पक्का करें कि आपने कम से कम iOS 9.0 और इसके बाद के वर्शन के लिए बनाया हो.

हमारा सुझाव है कि चौड़ाई और ऊंचाई की सीमाओं का इस्तेमाल करके, बैनर को ज़रूरी साइज़ तक सीमित करें.

अब GADBannerView की टॉप प्रॉपर्टी को सुरक्षित जगह के सबसे ऊपर की सीमा में रखकर, बैनर को सुरक्षित जगह के सबसे ऊपर अलाइन किया जा सकता है:

इसी तरह, GADBannerView की बॉटम प्रॉपर्टी को सुरक्षित जगह के सबसे नीचे की सीमा में रखकर, बैनर को सुरक्षित जगह के सबसे नीचे अलाइन किया जा सकता है:

आपकी सीमाएं, नीचे दिए गए स्क्रीनशॉट की तरह दिखनी चाहिए. हालांकि, साइज़/जगह अलग-अलग हो सकती है:

ViewController
यहां एक सामान्य व्यू कंट्रोलर कोड स्निपेट दिया गया है. इसकी मदद से, ऊपर दिए गए स्टोरीबोर्ड में कॉन्फ़िगर किए गए GADBannerView में बैनर दिखाया जा सकता है:
Swift
class ViewController: UIViewController { /// The banner view. @IBOutlet var bannerView: BannerView! override func viewDidLoad() { super.viewDidLoad() // Replace this ad unit ID with your own ad unit ID. bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716" bannerView.rootViewController = self bannerView.load(Request()) } }
Objective-C
@interface ViewController() @property(nonatomic, strong) IBOutlet GADBannerView *bannerView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Replace this ad unit ID with your own ad unit ID. self.bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; self.bannerView.rootViewController = self; GADRequest *request = [GADRequest request]; [self.bannerView loadRequest:request]; }
बैनर को सुरक्षित जगह के किनारे पर अलाइन करना
अगर आपको बैनर को बाईं या दाईं ओर अलाइन करना है, तो बैनर के बाएं/दाएं किनारे को सुपरव्यू के बाएं/दाएं किनारे के बजाय, सुरक्षित जगह के बाएं/दाएं किनारे पर रखें.
अगर आपने सुरक्षित जगह के लेआउट गाइड का इस्तेमाल करें विकल्प चालू किया है, तो व्यू में सीमाएं जोड़ते समय, इंटरफ़ेस बिल्डर डिफ़ॉल्ट रूप से सुरक्षित जगह के किनारों का इस्तेमाल करेगा.
प्रोग्रामेटिक
अगर आपका ऐप्लिकेशन, प्रोग्राम के ज़रिए बैनर विज्ञापन बनाता है, तो कोड में सीमाएं तय की जा सकती हैं और बैनर विज्ञापन को जगह दी जा सकती है. इस उदाहरण में, बैनर को सुरक्षित जगह के सबसे नीचे, बीच में अलाइन करने के लिए, सीमाएं तय करने का तरीका बताया गया है:
Swift
class ViewController: UIViewController { var bannerView: BannerView! override func viewDidLoad() { super.viewDidLoad() // Instantiate the banner view with your desired banner size. bannerView = BannerView(adSize: AdSizeBanner) addBannerViewToView(bannerView) bannerView.rootViewController = self // Set the ad unit ID to your own ad unit ID here. bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716" bannerView.load(Request()) } func addBannerViewToView(_ bannerView: UIView) { bannerView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(bannerView) if #available(iOS 11.0, *) { positionBannerAtBottomOfSafeArea(bannerView) } else { positionBannerAtBottomOfView(bannerView) } } @available (iOS 11, *) func positionBannerAtBottomOfSafeArea(_ bannerView: UIView) { // Position the banner. Stick it to the bottom of the Safe Area. // Centered horizontally. let guide: UILayoutGuide = view.safeAreaLayoutGuide NSLayoutConstraint.activate( [bannerView.centerXAnchor.constraint(equalTo: guide.centerXAnchor), bannerView.bottomAnchor.constraint(equalTo: guide.bottomAnchor)] ) } func positionBannerAtBottomOfView(_ bannerView: UIView) { // Center the banner horizontally. view.addConstraint(NSLayoutConstraint(item: bannerView, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0)) // Lock the banner to the top of the bottom layout guide. view.addConstraint(NSLayoutConstraint(item: bannerView, attribute: .bottom, relatedBy: .equal, toItem: self.bottomLayoutGuide, attribute: .top, multiplier: 1, constant: 0)) } }
Objective-C
@interface ViewController() @property(nonatomic, strong) GADBannerView *bannerView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Instantiate the banner view with your desired banner size. self.bannerView = [[GADBannerView alloc] initWithAdSize:GADAdSizeBanner]; [self addBannerViewToView:self.bannerView]; // Replace this ad unit ID with your own ad unit ID. self.bannerView.adUnitID = @"ca-app-pub-3940256099942544/2934735716"; self.bannerView.rootViewController = self; GADRequest *request = [GADRequest request]; [self.bannerView loadRequest:request]; } #pragma mark - view positioning -(void)addBannerViewToView:(UIView *_Nonnull)bannerView { self.bannerView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:self.bannerView]; if (@available(ios 11.0, *)) { [self positionBannerViewAtBottomOfSafeArea:bannerView]; } else { [self positionBannerViewAtBottomOfView:bannerView]; } } - (void)positionBannerViewAtBottomOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) { // Position the banner. Stick it to the bottom of the Safe Area. // Centered horizontally. UILayoutGuide *guide = self.view.safeAreaLayoutGuide; [NSLayoutConstraint activateConstraints:@[ [bannerView.centerXAnchor constraintEqualToAnchor:guide.centerXAnchor], [bannerView.bottomAnchor constraintEqualToAnchor:guide.bottomAnchor] ]]; } - (void)positionBannerViewAtBottomOfView:(UIView *_Nonnull)bannerView { [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; } @end
ऊपर बताई गई तकनीकों का इस्तेमाल करके, सुरक्षित जगह के सबसे ऊपर की सीमा में रखने के लिए, एट्रिब्यूट और ऐंकर में बदलाव किया जा सकता है.
स्मार्ट बैनर
अगर स्मार्ट बैनर का इस्तेमाल किया जा रहा है, तो हमारा सुझाव है कि लैंडस्केप मोड में, बैनर के किनारों को सुरक्षित जगह के बाएं और दाएं किनारों पर अलाइन करने के लिए, सीमाओं का इस्तेमाल करें.
इंटरफ़ेस बिल्डर में, iOS 9 से पहले के वर्शन में भी यह सुविधा उपलब्ध है. इसके लिए, ऊपर बताए गए तरीके से, सुरक्षित जगह के लेआउट गाइड का इस्तेमाल करें विकल्प पर सही का निशान लगाएं जैसा कि ऊपर बताया गया है.
कोड में, आपको अपने किनारे की सीमाओं को सुरक्षित जगह के लेआउट गाइड के हिसाब से बनाना चाहिए. यहां एक कोड स्निपेट दिया गया है. इससे व्यू में बैनर व्यू जोड़ा जाता है और इसे व्यू के सबसे नीचे, पूरी चौड़ाई में रखा जाता है:
Swift
func addBannerViewToView(_ bannerView: BannerView) { bannerView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(bannerView) if #available(iOS 11.0, *) { // In iOS 11, we need to constrain the view to the safe area. positionBannerViewFullWidthAtBottomOfSafeArea(bannerView) } else { // In lower iOS versions, safe area is not available so we use // bottom layout guide and view edges. positionBannerViewFullWidthAtBottomOfView(bannerView) } } // MARK: - view positioning @available (iOS 11, *) func positionBannerViewFullWidthAtBottomOfSafeArea(_ bannerView: UIView) { // Position the banner. Stick it to the bottom of the Safe Area. // Make it constrained to the edges of the safe area. let guide = view.safeAreaLayoutGuide NSLayoutConstraint.activate([ guide.leftAnchor.constraint(equalTo: bannerView.leftAnchor), guide.rightAnchor.constraint(equalTo: bannerView.rightAnchor), guide.bottomAnchor.constraint(equalTo: bannerView.bottomAnchor) ]) } func positionBannerViewFullWidthAtBottomOfView(_ bannerView: UIView) { view.addConstraint(NSLayoutConstraint(item: bannerView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: bannerView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: bannerView, attribute: .bottom, relatedBy: .equal, toItem: bottomLayoutGuide, attribute: .top, multiplier: 1, constant: 0)) }
Objective-C
- (void)addBannerViewToView:(UIView *)bannerView { bannerView.translatesAutoresizingMaskIntoConstraints = NO; [self.view addSubview:bannerView]; if (@available(ios 11.0, *)) { // In iOS 11, we need to constrain the view to the safe area. [self positionBannerViewFullWidthAtBottomOfSafeArea:bannerView]; } else { // In lower iOS versions, safe area is not available so we use // bottom layout guide and view edges. [self positionBannerViewFullWidthAtBottomOfView:bannerView]; } } #pragma mark - view positioning - (void)positionBannerViewFullWidthAtBottomOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) { // Position the banner. Stick it to the bottom of the Safe Area. // Make it constrained to the edges of the safe area. UILayoutGuide *guide = self.view.safeAreaLayoutGuide; [NSLayoutConstraint activateConstraints:@[ [guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor], [guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor], [guide.bottomAnchor constraintEqualToAnchor:bannerView.bottomAnchor] ]]; } - (void)positionBannerViewFullWidthAtBottomOfView:(UIView *_Nonnull)bannerView { [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]]; [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; }
नेटिव विज्ञापन
अगर आपका ऐप्लिकेशन, नेटिव विज्ञापनों को स्क्रीन के सबसे ऊपर या सबसे नीचे पिन करता है, तो नेटिव विज्ञापनों के लिए भी वही
सिद्धांत लागू होते हैं जो बैनर विज्ञापनों के लिए लागू होते हैं.
मुख्य अंतर यह है कि GADBannerView में सीमाएं जोड़ने के बजाय, आपको सुरक्षित जगह के लेआउट गाइड के हिसाब से, GADNativeAdView (या विज्ञापन के लिए कंटेनिंग व्यू) में सीमाएं जोड़नी होंगी. नेटिव व्यू के लिए, हमारा सुझाव है कि साइज़ की ज़्यादा साफ़ तौर पर सीमाएं तय करें.
इंटरस्टीशियल और इनाम वाले विज्ञापन
वर्शन 7.26.0 से, Google Mobile Ads SDK iPhone X के लिए इंटरस्टीशियल और इनाम वाले विज्ञापन फ़ॉर्मैट पूरी तरह से काम करते हैं.