-
Notifications
You must be signed in to change notification settings - Fork 4k
[firebase_admob] Support Native Ads on iOS #2106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0d0c05f
aad39a2
08bab20
3f0978e
0e073b4
2cc277a
25cbc59
10bcb6c
d6805db
7b16385
daeb8ec
5d19c10
c69e94c
abc4fee
73b0337
20e6cb6
03300ad
2211c63
ba01270
2cc1a0b
bf94993
af49fe7
1467913
b5392c9
d45f24d
ea4aef0
2fbe0ee
e15649e
c8e7796
3b43c89
a7011b4
a647bff
429df00
1166635
377be15
044e26e
7b191ec
1a4d891
a31908d
d20939c
bc3ffc7
846bb54
dca6b13
5b8caf4
d0c4e70
bf7d4c3
d40d2ac
0e14c8f
bfafb95
72e6254
bc4a1d8
d3d65b5
5effdc0
39fd92e
ebb7ff2
e88865c
f8462d5
d579020
e517e55
da2ef42
fc9cb32
287a756
4eba72c
cf2511c
29b2063
48acc40
c9e10b8
a583c5d
cd7d5f5
4a4706f
0897e36
717dba2
8270b94
1a4faee
3b30a1e
c7448b9
ab88c59
dfd19f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,9 @@ | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't typically include this file, but I need it to add |
||
/* Begin PBXBuildFile section */ | ||
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; | ||
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; | ||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; | ||
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; | ||
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; | ||
6E27B1151F0DAFA70028FD65 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 6E27B1141F0DAFA70028FD65 /* GoogleService-Info.plist */; }; | ||
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; | ||
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; | ||
8FC897F52411A9F100415930 /* UnifiedNativeAdView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8FC897F42411A9F100415930 /* UnifiedNativeAdView.xib */; }; | ||
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; | ||
9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; }; | ||
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; | ||
|
@@ -32,8 +28,6 @@ | |
dstPath = ""; | ||
dstSubfolderSpec = 10; | ||
files = ( | ||
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, | ||
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, | ||
); | ||
name = "Embed Frameworks"; | ||
runOnlyForDeploymentPostprocessing = 0; | ||
|
@@ -43,32 +37,30 @@ | |
/* Begin PBXFileReference section */ | ||
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; }; | ||
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; }; | ||
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; | ||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; }; | ||
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; }; | ||
6E27B1141F0DAFA70028FD65 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; }; | ||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; }; | ||
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; | ||
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; }; | ||
83F369F228D3A43519CEE308 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
8FC897F42411A9F100415930 /* UnifiedNativeAdView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = UnifiedNativeAdView.xib; sourceTree = "<group>"; }; | ||
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; }; | ||
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; }; | ||
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; }; | ||
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; | ||
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; }; | ||
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; | ||
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; | ||
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; | ||
CE82265EF05E2A9632B25E60 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; }; | ||
F74051031B69F8124E38352E /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; }; | ||
/* End PBXFileReference section */ | ||
|
||
/* Begin PBXFrameworksBuildPhase section */ | ||
97C146EB1CF9000F007C117D /* Frameworks */ = { | ||
isa = PBXFrameworksBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, | ||
3B80C3941E831B6300D905FE /* App.framework in Frameworks */, | ||
FBE669D215209F1F44CEEB21 /* libPods-Runner.a in Frameworks */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
|
@@ -79,6 +71,8 @@ | |
07A52D07C2C05D9527204891 /* Pods */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
CE82265EF05E2A9632B25E60 /* Pods-Runner.debug.xcconfig */, | ||
F74051031B69F8124E38352E /* Pods-Runner.release.xcconfig */, | ||
); | ||
name = Pods; | ||
sourceTree = "<group>"; | ||
|
@@ -94,10 +88,7 @@ | |
9740EEB11CF90186004384FC /* Flutter */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
3B80C3931E831B6300D905FE /* App.framework */, | ||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, | ||
2D5378251FAA1A9400D5DBA9 /* flutter_assets */, | ||
9740EEBA1CF902C7004384FC /* Flutter.framework */, | ||
9740EEB21CF90195004384FC /* Debug.xcconfig */, | ||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */, | ||
9740EEB31CF90195004384FC /* Generated.xcconfig */, | ||
|
@@ -127,6 +118,7 @@ | |
97C146F01CF9000F007C117D /* Runner */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
8FC897F42411A9F100415930 /* UnifiedNativeAdView.xib */, | ||
6E27B1141F0DAFA70028FD65 /* GoogleService-Info.plist */, | ||
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, | ||
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, | ||
|
@@ -193,6 +185,7 @@ | |
developmentRegion = English; | ||
hasScannedForEncodings = 0; | ||
knownRegions = ( | ||
English, | ||
en, | ||
Base, | ||
); | ||
|
@@ -214,8 +207,8 @@ | |
6E27B1151F0DAFA70028FD65 /* GoogleService-Info.plist in Resources */, | ||
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, | ||
9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */, | ||
8FC897F52411A9F100415930 /* UnifiedNativeAdView.xib in Resources */, | ||
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, | ||
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, | ||
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, | ||
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, | ||
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, | ||
|
@@ -255,7 +248,7 @@ | |
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
shellPath = /bin/sh; | ||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; | ||
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; | ||
}; | ||
9740EEB61CF901F6004384FC /* Run Script */ = { | ||
isa = PBXShellScriptBuildPhase; | ||
|
@@ -277,16 +270,13 @@ | |
files = ( | ||
); | ||
inputPaths = ( | ||
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", | ||
"${PODS_ROOT}/.symlinks/flutter/ios/Flutter.framework", | ||
); | ||
name = "[CP] Embed Pods Frameworks"; | ||
outputPaths = ( | ||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
shellPath = /bin/sh; | ||
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; | ||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; | ||
showEnvVarsInLog = 0; | ||
}; | ||
/* End PBXShellScriptBuildPhase section */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,67 @@ | |
// found in the LICENSE file. | ||
|
||
#include "AppDelegate.h" | ||
#import "FLTFirebaseAdMobPlugin.h" | ||
#include "GeneratedPluginRegistrant.h" | ||
|
||
@implementation AppDelegate | ||
@interface NativeAdFactoryExample : NSObject <FLTNativeAdFactory> | ||
@end | ||
|
||
// The UnifiedNativeAdView.xib and example GADUnifiedNativeAdView is provided and | ||
// explained by https://developers.google.com/admob/ios/native/advanced. | ||
@implementation NativeAdFactoryExample | ||
- (GADUnifiedNativeAdView *)createNativeAd:(GADUnifiedNativeAd *)nativeAd | ||
customOptions:(NSDictionary *)customOptions { | ||
// Create and place ad in view hierarchy. | ||
GADUnifiedNativeAdView *adView = | ||
[[NSBundle mainBundle] loadNibNamed:@"UnifiedNativeAdView" owner:nil options:nil].firstObject; | ||
|
||
// Associate the native ad view with the native ad object. This is | ||
// required to make the ad clickable. | ||
adView.nativeAd = nativeAd; | ||
|
||
// Populate the native ad view with the native ad assets. | ||
// The headline is guaranteed to be present in every native ad. | ||
((UILabel *)adView.headlineView).text = nativeAd.headline; | ||
|
||
// These assets are not guaranteed to be present. Check that they are before | ||
// showing or hiding them. | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this depend on the ad that is being displayed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this depends on the information that is provided in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Suggestion: what about we add a link to https://developers.google.com/admob/ios/native/advanced in a comment? |
||
((UILabel *)adView.bodyView).text = nativeAd.body; | ||
adView.bodyView.hidden = nativeAd.body ? NO : YES; | ||
|
||
[((UIButton *)adView.callToActionView) setTitle:nativeAd.callToAction | ||
forState:UIControlStateNormal]; | ||
adView.callToActionView.hidden = nativeAd.callToAction ? NO : YES; | ||
|
||
((UIImageView *)adView.iconView).image = nativeAd.icon.image; | ||
adView.iconView.hidden = nativeAd.icon ? NO : YES; | ||
|
||
((UILabel *)adView.storeView).text = nativeAd.store; | ||
adView.storeView.hidden = nativeAd.store ? NO : YES; | ||
|
||
((UILabel *)adView.priceView).text = nativeAd.price; | ||
adView.priceView.hidden = nativeAd.price ? NO : YES; | ||
|
||
((UILabel *)adView.advertiserView).text = nativeAd.advertiser; | ||
adView.advertiserView.hidden = nativeAd.advertiser ? NO : YES; | ||
|
||
// In order for the SDK to process touch events properly, user interaction | ||
// should be disabled. | ||
adView.callToActionView.userInteractionEnabled = NO; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this a requirement for Flutter apps? Is this meant to be set by the iOS embedding? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is required for any app that uses |
||
|
||
return adView; | ||
} | ||
@end | ||
|
||
@implementation AppDelegate | ||
- (BOOL)application:(UIApplication *)application | ||
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
[GeneratedPluginRegistrant registerWithRegistry:self]; | ||
// Override point for customization after application launch. | ||
|
||
NativeAdFactoryExample *nativeAdFactory = [[NativeAdFactoryExample alloc] init]; | ||
[FLTFirebaseAdMobPlugin registerNativeAdFactory:self | ||
factoryId:@"adFactoryExample" | ||
nativeAdFactory:nativeAdFactory]; | ||
return [super application:application didFinishLaunchingWithOptions:launchOptions]; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the example below has a
nativeAd
argument too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following the naming structure from apple docs. Example
setObject:forKey:
doesn't keep the name of the first object:https://developer.apple.com/documentation/foundation/nsmutabledictionary/1411616-setobject?language=objc
I wasn't really sure what the best shorthand form for an objective c method was.