-
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
[firebase_admob] Support Native Ads on iOS #2106
Conversation
…eAdView with custom layout.
…o native_ads_ios2
…e into native_ads_ios2
@@ -8,11 +8,11 @@ | |||
|
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.
We don't typically include this file, but I need it to add UnifiedNativeAdView.xib
to the xcode project. Otherwise, the app crashes when creating a NativeAd
.
packages/firebase_admob/README.md
Outdated
Android Native Ads require a class that implements `NativeAdFactory` which implements `createNativeAd( | ||
[UnifiedNativeAd](https://developers.google.com/android/reference/com/google/android/gms/ads/formats/UnifiedNativeAd) nativeAd, | ||
Map<String, Options> customOptions)` and returns a |
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.
This doesn't seem to render using GH markdown. Maybe add a link below to UnifiedNativeAd.
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.
done. I changed it to explain the method with the provided links. The signature of the method is still in the example below.
@@ -285,8 +285,53 @@ An example of displaying a `UnifiedNativeAd` with a `UnifiedNativeAdView` can be | |||
a custom layout and displays the test Native ad. | |||
|
|||
### iOS | |||
Native Ads for iOS require a class that implements the protocol `FLTNativeAdFactory` which has a | |||
single method `createNativeAd:customOptions:`. |
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.
packages/firebase_admob/README.md
Outdated
@end | ||
``` | ||
|
||
Once there is an implementation of `FLTNativeAdFactory` it must be added to the |
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: comma before it?
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.
done
|
||
// 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is required for any app that uses UnifiedNativeAdView
. Setting this to NO
is to guarantee that UnifiedNativeAdView
receives the touch event and not the subview. Otherwise, the adview wouldn't open the link.
nativeAdFactory:_nativeAdFactories[factoryId] | ||
customOptions:customOptions]; | ||
|
||
if (nativeAd.status != CREATED) { |
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.
should there be a return within this path? result
seems to be called twice if the ad isn't created.
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.
Yea there should be. I added one to the end of the if
statement.
@implementation FLTMobileAdWithView | ||
- (UIView *)adView { | ||
// We cause a crash if this method is not overriden by subclasses. | ||
[self doesNotRecognizeSelector:_cmd]; |
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.
Are developers going to be extending FLTMobileAdWithView on their own?
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.
Nope. Plugin users should never see this, but the plugin's maintainer would need to know this. I left this note so that another plugin maintainer knows why we cause a crash in this method.
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.
sounds good
[screen addSubview:self.adView]; | ||
|
||
#if defined(__IPHONE_11_0) && (__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0) | ||
if (@available(ios 11.0, *)) { |
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.
could you add a comment about why the constraints are needed on iOS 11?
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.
done
} | ||
#endif | ||
|
||
CGFloat x = |
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.
is this horizontally centering the ad and aligning it to the bottom? Could you add a comment?
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.
done
This is looking great! just a few nits. |
// These assets are not guaranteed to be present. Check that they are before | ||
// showing or hiding them. |
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.
does this depend on the ad that is being displayed?
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.
Yes this depends on the information that is provided in the UnifiedNativeAd
. Some ads may have this item and others won't.
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 see. Suggestion: what about we add a link to https://developers.google.com/admob/ios/native/advanced in a comment?
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.
LGTM + suggestion
// These assets are not guaranteed to be present. Check that they are before | ||
// showing or hiding them. |
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 see. Suggestion: what about we add a link to https://developers.google.com/admob/ios/native/advanced in a comment?
Description
Add support for Native Ads on iOS
Related Issues
Also fixes flutter/flutter#21634
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?