Skip to content

[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

Merged
merged 78 commits into from
Mar 17, 2020

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Mar 2, 2020

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • If the pull request affects only one plugin, the PR title starts with the name of the plugin in brackets (e.g. [cloud_firestore])
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@@ -8,11 +8,11 @@

Copy link
Contributor Author

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.

@bparrishMines bparrishMines changed the title [WIP] Native ads ios2 [firebase_admob] Support Native Ads on iOS Mar 9, 2020
@amirh
Copy link
Contributor

amirh commented Mar 10, 2020

@blasten

Comment on lines 198 to 200
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
Copy link

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.

Copy link
Contributor Author

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:`.
Copy link

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.

Copy link
Contributor Author

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.

@end
```

Once there is an implementation of `FLTNativeAdFactory` it must be added to the
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: comma before it?

Copy link
Contributor Author

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;
Copy link

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?

Copy link
Contributor Author

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) {
Copy link

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.

Copy link
Contributor Author

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];
Copy link

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?

Copy link
Contributor Author

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.

Copy link

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, *)) {
Copy link

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
#endif

CGFloat x =
Copy link

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@blasten
Copy link

blasten commented Mar 11, 2020

This is looking great! just a few nits.

Comment on lines +27 to +28
// These assets are not guaranteed to be present. Check that they are before
// showing or hiding them.
Copy link

@blasten blasten Mar 11, 2020

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?

Copy link
Contributor Author

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.

Copy link

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?

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM + suggestion

Comment on lines +27 to +28
// These assets are not guaranteed to be present. Check that they are before
// showing or hiding them.
Copy link

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The AdMob at the top is not displayed in the correct position.
4 participants