2016-05-11 5 views
5

के साथ AdMob मूल विज्ञापन दिखाएं मैं Google AdMob नेटवर्क से एडीएस मध्यस्थता के लिए MoPub SDK को एकीकृत कर रहा हूं। मैं अपने स्वयं के कस्टमएवेंट और एडाप्टर को लागू करने के बाद एडी को दिखाने के लिए प्राप्त कर सकता हूं, लेकिन मैं अपने आप पर क्लिक ईवेंट को संभालने के लिए एडी नहीं प्राप्त कर सकता। जब मैं AdMob देशी एडी पर क्लिक करता हूं, तो यह मुझे कहीं भी निर्देशित नहीं करेगा। फेसबुक और फ़्लुरी के कस्टमइवेंट और एडाप्टर का उपयोग करते समय, क्लिक स्वचालित रूप से संभाले जाते हैं। किसी को इस विषय पर कोई अनुभव है?MoPub (आईओएस)

अग्रिम में धन्यवाद। नीचे दिए गए कोड:

MPGoogleAdMobCustomEvent

@interface MPGoogleAdMobCustomEvent() 
@property(nonatomic, strong)GADAdLoader *loader; 
@end 

@implementation MPGoogleAdMobCustomEvent 

- (void)requestAdWithCustomEventInfo:(NSDictionary *)info 
{ 
    MPLogInfo(@"MOPUB: requesting AdMob Native Ad"); 

    NSString *adUnitID = [info objectForKey:@"adUnitID"]; 

    if (!adUnitID) { 

     [self.delegate nativeCustomEvent:self didFailToLoadAdWithError:MPNativeAdNSErrorForInvalidAdServerResponse(@"MOPUB: No AdUnitID from GoogleAdMob")]; 

     return; 
    } 

    self.loader = [[GADAdLoader alloc] initWithAdUnitID:adUnitID rootViewController:nil adTypes:@[kGADAdLoaderAdTypeNativeContent] options:nil]; 
    self.loader.delegate = self; 
    GADRequest *request = [GADRequest request]; 

#if (TARGET_OS_SIMULATOR) 

    request.testDevices = @[ kGADSimulatorID ]; 

#endif 

    CLLocation *location = [[CLLocationManager alloc] init].location; 
    if (location) { 
     [request setLocationWithLatitude:location.coordinate.latitude 
           longitude:location.coordinate.longitude 
           accuracy:location.horizontalAccuracy]; 
    } 
    request.requestAgent = @"MoPub"; 
    [self.loader loadRequest:request]; 
} 

- (void)adLoader:(GADAdLoader *)adLoader didReceiveNativeContentAd:(GADNativeContentAd *)nativeContentAd 
{ 
    MPLogDebug(@"MOPUB: Did receive nativeAd"); 

    MPGoogleAdMobNativeAdAdapter *adapter = [[MPGoogleAdMobNativeAdAdapter alloc] initWithGADNativeContentAd:nativeContentAd]; 
    adapter.url = nativeContentAd.advertiser; 
    MPNativeAd *interfaceAd = [[MPNativeAd alloc] initWithAdAdapter:adapter]; 

    NSMutableArray *imageArray = [NSMutableArray array]; 

    for (GADNativeAdImage *images in nativeContentAd.images) { 

     [imageArray addObject:images.imageURL]; 

    } 


    [super precacheImagesWithURLs:imageArray completionBlock:^(NSArray *errors) { 

     if ([errors count]) { 
      [self.delegate nativeCustomEvent:self didFailToLoadAdWithError:errors[0]]; 
     } else { 
      [self.delegate nativeCustomEvent:self didLoadAd:interfaceAd]; 
     } 

    }]; 
} 

- (void)adLoader:(GADAdLoader *)adLoader didFailToReceiveAdWithError:(GADRequestError *)error 
{ 
    MPLogDebug(@"MOPUB: AdMob ad failed to load with error (customEvent): %@", error.description); 
    [self.delegate nativeCustomEvent:self didFailToLoadAdWithError:error]; 
} 

@end 

MPGoogleAdMobNativeAdAdapter

@interface MPGoogleAdMobNativeAdAdapter()<GADNativeAdDelegate> 
@property(nonatomic, strong)NSDictionary *properties; 
@end 

@implementation MPGoogleAdMobNativeAdAdapter 

- (instancetype)initWithGADNativeContentAd:(GADNativeContentAd *)contentAD 
{ 
    self = [super init]; 
    if (self) { 
     self.contentAd = contentAD; 
     self.contentAd.delegate = self; 
     self.properties = [self convertAssetsToProperties:contentAD]; 
    } 
    return self; 
} 

- (NSDictionary *)convertAssetsToProperties:(GADNativeContentAd *)adNative 
{ 
    self.contentAd = adNative; 
    NSMutableDictionary * dictionary = [NSMutableDictionary dictionary]; 
    if (adNative.headline) { 
     dictionary[kAdTitleKey] = adNative.headline; 
    } 
    if (adNative.body) { 
     dictionary[kAdTextKey] = adNative.body; 
    } 
    if (adNative.images[0]) { 
     dictionary[kAdMainImageKey] = ((GADNativeAdImage *)adNative.images[0]).imageURL.absoluteString; 
    } 
    if (adNative.callToAction) { 
     dictionary[kAdCTATextKey] = adNative.callToAction; 
    } 
    return [dictionary copy]; 
} 

#pragma mark MPNativeAdAdapter 
- (NSTimeInterval)requiredSecondsForImpression 
{ 
    return 0.0; 
} 

- (NSURL *)defaultActionURL 
{ 
    return nil; 
} 

- (BOOL)enableThirdPartyClickTracking 
{ 
    return YES; 
} 


- (void)willAttachToView:(UIView *)view 
{ 
    self.contentAd.rootViewController = [self.delegate viewControllerForPresentingModalView]; 
} 

- (void)didDetachFromView:(UIView *)view 
{ 
    self.contentAd.rootViewController = nil; 
} 

#pragma mark GADNativeAdDelegate 

- (void)nativeAdWillPresentScreen:(GADNativeAd *)nativeAd 
{ 
    if ([self.delegate respondsToSelector:@selector(nativeAdWillPresentModalForAdapter:)]) { 
     [self.delegate nativeAdWillPresentModalForAdapter:self]; 
    } 
} 

- (void)nativeAdDidDismissScreen:(GADNativeAd *)nativeAd 
{ 
    if ([self.delegate respondsToSelector:@selector(nativeAdDidDismissModalForAdapter:)]) { 
     [self.delegate nativeAdDidDismissModalForAdapter:self]; 
    } 
} 

- (void)nativeAdWillLeaveApplication:(GADNativeAd *)nativeAd 
{ 
    if ([self.delegate respondsToSelector:@selector(nativeAdWillLeaveApplicationFromAdapter:)]) { 
     [self.delegate nativeAdWillLeaveApplicationFromAdapter:self]; 
    } 
} 

@end 




` 

उत्तर

0

आप AdMob विज्ञापन के लिए अपने कस्टम यूआई हो रही है, फिर वहाँ एक बटन है जो आप callToAction भाग के लिए उपयोग किया जाएगा किया जाएगा।

आप सभी, क्लिक का पता लगाने के लिए कार्रवाई है कि बटन के लिए चयनकर्ता जोड़ने

[callToActionButton addTarget:self action:@selector(adCalled:) forControlEvents:UIControlEventTouchUpInside]; 

कि adCalled विधि को लागू करने के बाद क्लिक & कॉल प्राप्त करने का विधि आगे करने के लिए एक चयनकर्ता जोड़ने की जरूरत है सबसे पहले, नीचे आपके संदर्भ के लिए कोड है उदाहरण नीचे मैंने अपने संग्रह दृश्य & से विज्ञापन ऑब्जेक्ट प्राप्त करने के लिए उपयोग किया है, तो मैं इसे पुनर्निर्देशित कर रहा हूं।

- (void)adCalled:(id)sender 
{ 
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:mainCollectionView]; // Get the button position 
    NSIndexPath *indexPath = [collectionView indexPathForItemAtPoint:buttonPosition]; // Get the index path of button so that I can retrieve the correct ad object 
    id selectedAd = [adArray objectAtIndex:indexPath.row]; 
    if ([selectedAd isKindOfClass:[GADNativeContentAd class]]) { 
     NSString *url = [selectedAd valueForKey:@"googleClickTrackingURLString"]; 
     NSLog(@"URL is :%@", url); 
     NSURL *googleUrl = [NSURL URLWithString:url]; 
     if ([[UIApplication sharedApplication] canOpenURL: googleUrl]) { 
      [[UIApplication sharedApplication] openURL:googleUrl]; 
     } 
    } 
} 

इसका उपयोग करके मैं Google ट्रैकिंग यूआरएल का उपयोग करके लिंक एन वेब खोल सकता हूं।

उम्मीद है कि इससे मदद मिलती है।