Skip to content

Commit 4639070

Browse files
Merge pull request #30 from kmcgill88/add-ios-support
Add iOS Support
2 parents 71c6fb4 + 1cdfe13 commit 4639070

20 files changed

+739
-51
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
pubspec.lock
77

88
build/
9+
.idea

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
## [0.2.0] - 2019/04/04
1+
## [0.3.0] - 2019/05/28
2+
Add iOS support!
23

4+
## [0.2.0] - 2019/04/04
35
Update to AndroidX.
6+
> **Note:** This is a breaking change on Android!
47
58
## [0.1.2] - Dec 10
6-
79
* Release first version

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ISC License
22

33
Copyright (c) 2018, Youssef Kababe
4+
Copyright (c) 2019, Kevin McGill <[email protected]>
45

56
Permission to use, copy, modify, and/or distribute this software for any
67
purpose with or without fee is hereby granted, provided that the above

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,19 @@ This plugin also has support for Interstitial and Reward ads.
1414

1515
This is an early version of the plugin, my primary goal was to overcome the banner ads positioning limitations by implementing a platform views solution, and keeping things simple and stupid because I'm still learning about many Flutter related stuff. I will actively work on adding missing features, improving, and refactoring the code in my free time.
1616

17-
**Currently working on Android only, but iOS support will be available so soon.**
18-
19-
## Installation
17+
# Installation
2018

2119
Add this to your pubspec.yml dependencies:
2220

2321
```yaml
24-
admob_flutter: "^0.2.0"
22+
admob_flutter: "^0.3.0"
2523
```
26-
## Suport
27-
- AndroidX
24+
### Supported Platforms
25+
- `0.3.0` >= iOS
26+
- `0.2.0` >= AndroidX
2827
- FlutterSdk >=2.1.0 < 3.0.0
29-
## How to use
3028

29+
## Android
3130
### Update your AndroidManifest.xml
3231

3332
Add your AdMob App ID to your app's AndroidManifest.xml file by adding the <meta-data> tag shown below. You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.
@@ -46,7 +45,19 @@ ca-app-pub-3940256099942544~3347511713
4645
</application>
4746
</manifest>
4847
```
48+
## iOS
49+
Update your `Info.plist` per [Firebase instructions](https://developers.google.com/admob/ios/quick-start#update_your_infoplist).
50+
```xml
51+
<key>GADApplicationIdentifier</key>
52+
<string>ca-app-pub-3940256099942544~1458002511</string>
53+
```
54+
and add
55+
```xml
56+
<key>io.flutter.embedded_views_preview</key>
57+
<true/>
58+
```
4959

60+
# How to use
5061
### Initialize the plugin
5162

5263
First thing to do before attempting to show any ads is to initialize the plugin. You can do this in the earliest starting point of your app, your `main` function:
@@ -55,7 +66,7 @@ First thing to do before attempting to show any ads is to initialize the plugin.
5566
import 'package:admob_flutter/admob_flutter.dart';
5667
5768
void main() {
58-
Admob.initialize('ca-app-pub-3940256099942544~3347511713');
69+
Admob.initialize(getAppId());
5970
runApp(MyApp());
6071
}
6172
```
@@ -66,7 +77,7 @@ This plugin uses Native Platform Views to show Admob banner ads thus, same as an
6677

6778
```dart
6879
AdmobBanner(
69-
adUnitId: 'ca-app-pub-3940256099942544/6300978111',
80+
adUnitId: getBannerAdUnitId(),
7081
adSize: AdmobBannerSize.BANNER,
7182
)
7283
```
@@ -88,7 +99,7 @@ You can attach a listener to your ads in order to customize their behavior like
8899

89100
```dart
90101
AdmobBanner(
91-
adUnitId: 'ca-app-pub-3940256099942544/6300978111',
102+
adUnitId: getBannerAdUnitId(),
92103
adSize: AdmobBannerSize.BANNER,
93104
listener: (AdmobAdEvent event, Map<String, dynamic> args) {
94105
switch (event) {
@@ -117,7 +128,7 @@ AdmobBanner(
117128
```dart
118129
// First, create an interstitial ad
119130
AdmobInterstitial interstitialAd = AdmobInterstitial(
120-
adUnitId: 'ca-app-pub-3940256099942544/1033173712',
131+
adUnitId: getInterstitialAdUnitId(),
121132
);
122133
123134
// Interstitials must be loaded before shown.
@@ -148,7 +159,7 @@ You can do something like this (Don't do it!):
148159
AdmobInterstitial interstitialAd;
149160
150161
interstitialAd = AdmobInterstitial(
151-
adUnitId: 'ca-app-pub-3940256099942544/1033173712',
162+
adUnitId: getInterstitialAdUnitId(),
152163
listener: (AdmobAdEvent event, Map<String, dynamic> args) {
153164
if (event == AdmobAdEvent.loaded) interstitialAd.show();
154165
if (event == AdmobAdEvent.closed) interstitialAd.load();
@@ -165,7 +176,7 @@ interstitialAd = AdmobInterstitial(
165176
```dart
166177
// First, create a reward ad
167178
AdmobReward rewardAd = AdmobReward(
168-
adUnitId: 'ca-app-pub-3940256099942544/5224354917',
179+
adUnitId: getRewardBasedVideoAdUnitId(),
169180
);
170181
171182
// Reward ads must be loaded before shown.
@@ -188,7 +199,7 @@ Listening to reward ads events works the same as with banners and interstitials,
188199

189200
```dart
190201
AdmobReward rewardAd = AdmobReward(
191-
adUnitId: 'ca-app-pub-3940256099942544/5224354917',
202+
adUnitId: getRewardBasedVideoAdUnitId(),
192203
listener: (AdmobAdEvent event, Map<String, dynamic> args) {
193204
if (event == AdmobAdEvent.rewarded) {
194205
print('User was rewarded!');
@@ -200,9 +211,7 @@ AdmobReward rewardAd = AdmobReward(
200211
```
201212

202213
### Showing Native Ads
203-
204214
**Coming soon!**
205215

206216
### Using targeting info
207-
208217
**Coming soon!**

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
platform :ios, '8.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
11-
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
1211
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1312
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1413
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -19,6 +18,7 @@
1918
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
2019
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
2120
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
21+
E7A1118201BCA9D718CC3ED4 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24D7FA5CEB975A68FF05067C /* Pods_Runner.framework */; };
2222
/* End PBXBuildFile section */
2323

2424
/* Begin PBXCopyFilesBuildPhase section */
@@ -39,9 +39,10 @@
3939
/* Begin PBXFileReference section */
4040
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4141
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
42-
2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; };
42+
24D7FA5CEB975A68FF05067C /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4343
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4444
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
45+
60E4F89FB3CA779FE21111C3 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
4546
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
4647
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4748
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
@@ -53,6 +54,8 @@
5354
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5455
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
5556
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
57+
9F4D6C33C6C390F42E506F21 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
58+
A09C8DAD180952151FDA7CAA /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
5659
/* End PBXFileReference section */
5760

5861
/* Begin PBXFrameworksBuildPhase section */
@@ -62,16 +65,27 @@
6265
files = (
6366
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
6467
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
68+
E7A1118201BCA9D718CC3ED4 /* Pods_Runner.framework in Frameworks */,
6569
);
6670
runOnlyForDeploymentPostprocessing = 0;
6771
};
6872
/* End PBXFrameworksBuildPhase section */
6973

7074
/* Begin PBXGroup section */
75+
462490AC19C85F5B12038C68 /* Pods */ = {
76+
isa = PBXGroup;
77+
children = (
78+
60E4F89FB3CA779FE21111C3 /* Pods-Runner.debug.xcconfig */,
79+
9F4D6C33C6C390F42E506F21 /* Pods-Runner.release.xcconfig */,
80+
A09C8DAD180952151FDA7CAA /* Pods-Runner.profile.xcconfig */,
81+
);
82+
name = Pods;
83+
path = Pods;
84+
sourceTree = "<group>";
85+
};
7186
9740EEB11CF90186004384FC /* Flutter */ = {
7287
isa = PBXGroup;
7388
children = (
74-
2D5378251FAA1A9400D5DBA9 /* flutter_assets */,
7589
3B80C3931E831B6300D905FE /* App.framework */,
7690
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
7791
9740EEBA1CF902C7004384FC /* Flutter.framework */,
@@ -88,6 +102,8 @@
88102
9740EEB11CF90186004384FC /* Flutter */,
89103
97C146F01CF9000F007C117D /* Runner */,
90104
97C146EF1CF9000F007C117D /* Products */,
105+
462490AC19C85F5B12038C68 /* Pods */,
106+
9AC3B6257E801133BCE0A190 /* Frameworks */,
91107
);
92108
sourceTree = "<group>";
93109
};
@@ -122,19 +138,29 @@
122138
name = "Supporting Files";
123139
sourceTree = "<group>";
124140
};
141+
9AC3B6257E801133BCE0A190 /* Frameworks */ = {
142+
isa = PBXGroup;
143+
children = (
144+
24D7FA5CEB975A68FF05067C /* Pods_Runner.framework */,
145+
);
146+
name = Frameworks;
147+
sourceTree = "<group>";
148+
};
125149
/* End PBXGroup section */
126150

127151
/* Begin PBXNativeTarget section */
128152
97C146ED1CF9000F007C117D /* Runner */ = {
129153
isa = PBXNativeTarget;
130154
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
131155
buildPhases = (
156+
0C24A2A7747A18E0525C5E7D /* [CP] Check Pods Manifest.lock */,
132157
9740EEB61CF901F6004384FC /* Run Script */,
133158
97C146EA1CF9000F007C117D /* Sources */,
134159
97C146EB1CF9000F007C117D /* Frameworks */,
135160
97C146EC1CF9000F007C117D /* Resources */,
136161
9705A1C41CF9048500538489 /* Embed Frameworks */,
137162
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
163+
7FDF1B0DB9C66D50FD638659 /* [CP] Embed Pods Frameworks */,
138164
);
139165
buildRules = (
140166
);
@@ -187,14 +213,35 @@
187213
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
188214
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
189215
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */,
190-
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */,
191216
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */,
192217
);
193218
runOnlyForDeploymentPostprocessing = 0;
194219
};
195220
/* End PBXResourcesBuildPhase section */
196221

197222
/* Begin PBXShellScriptBuildPhase section */
223+
0C24A2A7747A18E0525C5E7D /* [CP] Check Pods Manifest.lock */ = {
224+
isa = PBXShellScriptBuildPhase;
225+
buildActionMask = 2147483647;
226+
files = (
227+
);
228+
inputFileListPaths = (
229+
);
230+
inputPaths = (
231+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
232+
"${PODS_ROOT}/Manifest.lock",
233+
);
234+
name = "[CP] Check Pods Manifest.lock";
235+
outputFileListPaths = (
236+
);
237+
outputPaths = (
238+
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
239+
);
240+
runOnlyForDeploymentPostprocessing = 0;
241+
shellPath = /bin/sh;
242+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
243+
showEnvVarsInLog = 0;
244+
};
198245
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
199246
isa = PBXShellScriptBuildPhase;
200247
buildActionMask = 2147483647;
@@ -209,6 +256,28 @@
209256
shellPath = /bin/sh;
210257
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
211258
};
259+
7FDF1B0DB9C66D50FD638659 /* [CP] Embed Pods Frameworks */ = {
260+
isa = PBXShellScriptBuildPhase;
261+
buildActionMask = 2147483647;
262+
files = (
263+
);
264+
inputPaths = (
265+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
266+
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
267+
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
268+
"${BUILT_PRODUCTS_DIR}/nanopb/nanopb.framework",
269+
);
270+
name = "[CP] Embed Pods Frameworks";
271+
outputPaths = (
272+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
273+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
274+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/nanopb.framework",
275+
);
276+
runOnlyForDeploymentPostprocessing = 0;
277+
shellPath = /bin/sh;
278+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
279+
showEnvVarsInLog = 0;
280+
};
212281
9740EEB61CF901F6004384FC /* Run Script */ = {
213282
isa = PBXShellScriptBuildPhase;
214283
buildActionMask = 2147483647;
@@ -512,7 +581,6 @@
512581
defaultConfigurationName = Release;
513582
};
514583
/* End XCConfigurationList section */
515-
516584
};
517585
rootObject = 97C146E61CF9000F007C117D /* Project object */;
518586
}

example/ios/Runner.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildSystemType</key>
6+
<string>Original</string>
7+
</dict>
8+
</plist>

example/ios/Runner/Info.plist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>io.flutter.embedded_views_preview</key>
6+
<true/>
7+
<key>LSApplicationCategoryType</key>
8+
<string></string>
9+
<key>GADApplicationIdentifier</key>
10+
<string>ca-app-pub-3940256099942544~1458002511</string>
511
<key>CFBundleDevelopmentRegion</key>
612
<string>en</string>
713
<key>CFBundleExecutable</key>

0 commit comments

Comments
 (0)