-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of ssh://stash.corp.appnexus.com:7999/mobile-sd…
…k/app_mobile-sdk-ios
- Loading branch information
Showing
113 changed files
with
8,313 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* Copyright 2020 APPNEXUS INC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#if __has_include(<AppNexusNativeSDK/AppNexusNativeSDK.h>) | ||
#import <AppNexusNativeSDK/AppNexusNativeSDK.h> | ||
#elif __has_include(<AppNexusSDK/AppNexusSDK.h>) | ||
#import <AppNexusSDK/AppNexusSDK.h> | ||
#else | ||
#import "ANNativeCustomAdapter.h" | ||
#import "ANLogging.h" | ||
#import "ANCSRNativeAdResponse.h" | ||
#endif | ||
#import <FBAudienceNetwork/FBAudienceNetwork.h> | ||
|
||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface ANAdAdapterCSRNativeBannerFacebook : NSObject | ||
|
||
/*! | ||
* Should be called when the CSRNativeBannerAd view has been populated with the ad elements and will be displayed. | ||
* Clicks will be handled automatically. If the view is already registered with another ANNativeAdResponse, | ||
* it will be automatically detached from that response before being attached to this response. | ||
* | ||
*/ | ||
|
||
/* | ||
* @param view The view which is populated with the native ad elements. Must not be nil. | ||
* @param controller The root view controller which contains the view. Must not be nil. | ||
* @param iconView The FBMediaView you created to render the icon. | ||
* @param clickableViews Specifies view subviews which should be clickable, instead of the whole view (the default). May be nil. | ||
* @note The response holds a strong reference to the registered view. | ||
*/ | ||
|
||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconView:(FBMediaView *_Nonnull)iconView | ||
clickableViews:(nullable NSArray *)clickableViews; | ||
|
||
|
||
/*! | ||
* @param view The view which is populated with the native ad elements. Must not be nil. | ||
* @param controller The root view controller which contains the view. Must not be nil. | ||
* @param iconImageView The UIImageView you created to render the icon. | ||
* @param clickableViews Specifies view subviews which should be clickable, instead of the whole view (the default). May be nil. | ||
* @note The response holds a strong reference to the registered view. | ||
*/ | ||
|
||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconImageView:(UIImageView *_Nonnull)iconImageView | ||
clickableViews:(nullable NSArray *)clickableViews; | ||
|
||
|
||
/* | ||
* @param view The view which is populated with the native ad elements. Must not be nil. | ||
* @param controller The root view controller which contains the view. Must not be nil. | ||
* @param iconView The FBMediaView you created to render the icon. | ||
* @note The response holds a strong reference to the registered view. | ||
*/ | ||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconView:(FBMediaView *_Nonnull)iconView; | ||
|
||
|
||
|
||
/*! | ||
* @param view The view which is populated with the native ad elements. Must not be nil. | ||
* @param controller The root view controller which contains the view. Must not be nil. | ||
* @param iconImageView The UIImageView you created to render the icon. | ||
* @note The response holds a strong reference to the registered view. | ||
*/ | ||
|
||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconImageView:(UIImageView *_Nonnull)iconImageView; | ||
|
||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/* Copyright 2020 APPNEXUS INC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import "ANAdAdapterCSRNativeBannerFacebook.h" | ||
@import FBAudienceNetwork; | ||
|
||
@protocol ANCSRNativeAdRequestAdDelegate; | ||
|
||
|
||
|
||
@interface ANAdAdapterCSRNativeBannerFacebook () <FBNativeBannerAdDelegate , ANNativeCustomAdapter> | ||
|
||
@property (nonatomic, strong) FBNativeBannerAd *nativeBannerAd; | ||
@property (nonatomic) FBMediaView *fbAdMediaViewIcon; | ||
@property (nonatomic) UIImageView *fbAdImageViewIcon; | ||
@property (nonatomic , weak) ANCSRNativeAdResponse *csrNativeAdResponse; | ||
|
||
@end | ||
|
||
@implementation ANAdAdapterCSRNativeBannerFacebook | ||
|
||
@synthesize requestDelegate; | ||
@synthesize nativeAdDelegate; | ||
@synthesize expired; | ||
|
||
- (void) requestAdwithPayload:(nonnull NSString *) payload targetingParameters:(nullable ANTargetingParameters *)targetingParameters{ | ||
|
||
NSString *placement = [self getPlacementIdFrom:payload]; | ||
FBNativeBannerAd *nativeBannerAd = [[FBNativeBannerAd alloc] | ||
initWithPlacementID:placement]; | ||
|
||
// Set a delegate to get notified when the ad was loaded. | ||
nativeBannerAd.delegate = self; | ||
// Initiate a request to load an ad. | ||
[nativeBannerAd loadAdWithBidPayload:payload]; | ||
} | ||
|
||
-(NSString *)getPlacementIdFrom:(NSString *)payload{ | ||
NSData *data = [payload dataUsingEncoding:NSUTF8StringEncoding]; | ||
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; | ||
return json[@"placement_id"]; | ||
} | ||
|
||
- (void)nativeBannerAdDidLoad:(FBNativeBannerAd *)nativeBannerAd | ||
{ | ||
self.nativeBannerAd = nativeBannerAd; | ||
[self showNativeBannerAd]; | ||
} | ||
|
||
- (void)showNativeBannerAd | ||
{ | ||
ANLogDebug(@"Ad did receive FacebookNativeBannerAd."); | ||
|
||
ANCSRNativeAdResponse *csrNativeAdResponse = [[ANCSRNativeAdResponse alloc] initWithCustomAdapter:self | ||
networkCode:ANNativeAdNetworkCodeFacebook]; | ||
csrNativeAdResponse.title = self.nativeBannerAd.headline; | ||
csrNativeAdResponse.body = self.nativeBannerAd.bodyText; | ||
csrNativeAdResponse.callToAction = self.nativeBannerAd.callToAction; | ||
csrNativeAdResponse.customElements = @{ kANNativeCSRObject : self , kANNativeElementObject : self.nativeBannerAd}; | ||
self.csrNativeAdResponse = csrNativeAdResponse; | ||
[self.requestDelegate didLoadNativeAd:self.csrNativeAdResponse]; | ||
} | ||
|
||
#pragma mark FBNativeBannerAdDelegate | ||
|
||
- (void)nativeBannerAdDidDownloadMedia:(FBNativeBannerAd *)nativeBannerAd{ | ||
ANLogDebug(@"FacebookNativeBannerAd did download media"); | ||
} | ||
|
||
- (void)nativeBannerAdWillLogImpression:(FBNativeBannerAd *)nativeBannerAd{ | ||
ANLogDebug(@"FacebookNativeBannerAd impression is being captured."); | ||
[self.nativeAdDelegate adDidLogImpression]; | ||
} | ||
|
||
- (void)nativeBannerAd:(FBNativeBannerAd *)nativeBannerAd didFailWithError:(NSError *)error{ | ||
ANLogError(@"Error loading Facebook banner native ad: %@", error); | ||
ANAdResponseCode code = ANAdResponseInternalError; | ||
if (error.code == 1001) { | ||
code = ANAdResponseUnableToFill; | ||
} | ||
[self.requestDelegate didFailToLoadNativeAd:code]; | ||
} | ||
|
||
- (void)nativeBannerAdDidFinishHandlingClick:(FBNativeBannerAd *)nativeBannerAd{ | ||
ANLogDebug(@"FacebookNativeBannerAd did finish handling click"); | ||
} | ||
|
||
- (void)nativeBannerAdDidClick:(FBNativeBannerAd *)nativeBannerAd | ||
{ | ||
ANLogDebug(@"FacebookNativeBannerAd ad was clicked."); | ||
[self.nativeAdDelegate adWasClicked]; | ||
} | ||
|
||
|
||
|
||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconView:(FBMediaView *_Nonnull)iconView | ||
clickableViews:(nullable NSArray *)clickableViews{ | ||
|
||
if(![self hasExpired]){ | ||
[self registerNativeAdDelegate]; | ||
[self.nativeBannerAd registerViewForInteraction:view | ||
iconView:iconView | ||
viewController:controller | ||
clickableViews:clickableViews]; | ||
} | ||
else{ | ||
ANLogDebug(@"FacebookNativeBannerAd is expired."); | ||
} | ||
} | ||
|
||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconImageView:(UIImageView *_Nonnull)iconImageView | ||
clickableViews:(nullable NSArray *)clickableViews{ | ||
|
||
if(![self hasExpired] ){ | ||
[self registerNativeAdDelegate]; | ||
[self.nativeBannerAd registerViewForInteraction:view | ||
iconImageView:iconImageView | ||
viewController:controller | ||
clickableViews:clickableViews]; | ||
} | ||
else{ | ||
ANLogDebug(@"FacebookNativeBannerAd is expired."); | ||
} | ||
} | ||
|
||
|
||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconView:(FBMediaView *_Nonnull)iconView{ | ||
if(![self hasExpired]){ | ||
[self registerNativeAdDelegate]; | ||
[self.nativeBannerAd registerViewForInteraction:view | ||
iconView:iconView | ||
viewController:controller]; | ||
} | ||
else{ | ||
ANLogDebug(@"FacebookNativeBannerAd is expired."); | ||
} | ||
} | ||
|
||
- (void)registerViewForTracking:(nonnull UIView *)view | ||
withRootViewController:(nonnull UIViewController *)controller | ||
iconImageView:(UIImageView *_Nonnull)iconImageView{ | ||
|
||
if(![self hasExpired]){ | ||
[self registerNativeAdDelegate]; | ||
[self.nativeBannerAd registerViewForInteraction:view | ||
iconImageView:iconImageView | ||
viewController:controller]; | ||
} | ||
else{ | ||
ANLogDebug(@"FacebookNativeBannerAd is expired."); | ||
} | ||
} | ||
|
||
- (void)dealloc { | ||
[self unregisterViewFromTracking]; | ||
} | ||
|
||
- (BOOL)hasExpired { | ||
return ![self.nativeBannerAd isAdValid]; | ||
} | ||
|
||
- (void)unregisterViewFromTracking { | ||
[self.nativeBannerAd unregisterView]; | ||
self.nativeBannerAd = nil; | ||
self.csrNativeAdResponse = nil; | ||
} | ||
|
||
- (void)registerNativeAdDelegate { | ||
if(self.csrNativeAdResponse != nil && self.csrNativeAdResponse.adapter!= nil){ | ||
self.csrNativeAdResponse.adapter.nativeAdDelegate = self.csrNativeAdResponse; | ||
[self.csrNativeAdResponse registerOMID]; | ||
} | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* Copyright 2020 APPNEXUS INC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
|
||
#import <Foundation/Foundation.h> | ||
#import <FBAudienceNetwork/FBAudienceNetwork.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface ANFBSettings : NSObject | ||
+ (NSString *)getBidderToken; | ||
@end | ||
|
||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Copyright 2020 APPNEXUS INC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import <FBAudienceNetwork/FBAudienceNetwork.h> | ||
#import "ANFBSettings.h" | ||
|
||
@implementation ANFBSettings | ||
|
||
+ (NSString *)getBidderToken{ | ||
return [FBAdSettings bidderToken]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.