Skip to content

Commit 14c5563

Browse files
author
Stewart Miles
committed
Integrate Latest @ 118793277
Changes to admob/testapp ... - Add Future interface to admob. Changes to messaging/testapp ... - Added a readme for local testing - Making the iOS implementation of Initialization run on the main thread. CL: 118793277
1 parent e816bb5 commit 14c5563

File tree

2 files changed

+193
-14
lines changed

2 files changed

+193
-14
lines changed

admob/testapp/src/common_main.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static const char* kExtraValue = "the_value_for_that_extra";
5252

5353
// Global vars.
5454
::firebase::App* g_app;
55-
::firebase::admob::BannerView* g_banner;
56-
::firebase::admob::InterstitialAd* g_int;
55+
::firebase::admob::BannerView g_banner;
56+
::firebase::admob::InterstitialAd g_int;
5757
::firebase::admob::AdRequest g_request;
5858

5959
// Extras to use later
@@ -125,12 +125,12 @@ extern "C" int common_main(void* ad_parent) {
125125
ad_size.height = kBannerHeight;
126126

127127
LogMessage("Creating the BannerView.");
128-
g_banner = new admob::BannerView(static_cast<admob::AdParent>(ad_parent),
129-
kBannerAdUnit, ad_size);
128+
g_banner.Initialize(static_cast<admob::AdParent>(ad_parent), kBannerAdUnit,
129+
ad_size);
130130

131131
LogMessage("Creating the InterstitialAd.");
132-
g_int = new admob::InterstitialAd(static_cast<admob::AdParent>(ad_parent),
133-
kInterstitialAdUnit);
132+
g_int.Initialize(static_cast<admob::AdParent>(ad_parent),
133+
kInterstitialAdUnit);
134134

135135
#if defined(__ANDROID__)
136136
while (!ProcessAndroidEvents(1000)) {
@@ -139,13 +139,13 @@ extern "C" int common_main(void* ad_parent) {
139139
#endif // defined(__ANDROID__)
140140

141141
admob::BannerView::BannerViewPresentationState banner_presentation =
142-
g_banner->GetPresentationState();
142+
g_banner.GetPresentationState();
143143
admob::BannerView::BannerViewLifecycleState banner_lifecycle =
144-
g_banner->GetLifecycleState();
144+
g_banner.GetLifecycleState();
145145
admob::InterstitialAd::InterstitialAdPresentationState
146-
interstitial_presentation = g_int->GetPresentationState();
146+
interstitial_presentation = g_int.GetPresentationState();
147147
admob::InterstitialAd::InterstitialAdLifecycleState interstitial_lifecycle =
148-
g_int->GetLifecycleState();
148+
g_int.GetLifecycleState();
149149

150150
LogMessage("BannerView status: %d, %d -- InterstitialAd status: %d, %d",
151151
banner_presentation, banner_lifecycle, interstitial_presentation,
@@ -154,15 +154,15 @@ extern "C" int common_main(void* ad_parent) {
154154
// When the BannerView is initialized, load an ad and show it.
155155
if (banner_lifecycle == admob::BannerView::kBannerViewInitialized) {
156156
LogMessage("Loading banner ad...");
157-
g_banner->LoadAd(g_request);
158-
g_banner->Show();
157+
g_banner.LoadAd(g_request);
158+
g_banner.Show();
159159
}
160160

161161
// When the InterstitialAd is initialized, load an ad.
162162
if (interstitial_lifecycle ==
163163
admob::InterstitialAd::kInterstitialAdInitialized) {
164164
LogMessage("Loading interstitial ad...");
165-
g_int->LoadAd(g_request);
165+
g_int.LoadAd(g_request);
166166
}
167167

168168
// When the InterstitialAd is loaded and not yet shown, show it.
@@ -171,7 +171,7 @@ extern "C" int common_main(void* ad_parent) {
171171
(interstitial_presentation ==
172172
admob::InterstitialAd::kInterstitialAdHidden)) {
173173
LogMessage("Showing interstitial ad...");
174-
g_int->Show();
174+
g_int.Show();
175175
}
176176

177177
// If both the BannerView and InterstitialAd are successfully showing, exit.

messaging/testapp/readme.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
Firebase Cloud Messaging Quickstart
2+
===================================
3+
4+
The Firebase Cloud Messaging Test Application (testapp) demonstrates receiving
5+
Firebase Cloud Messages using the Firebase Cloud Messaging C++ SDK. This
6+
application has no user interface and simply logs actions it's performing to the
7+
console.
8+
9+
Introduction
10+
------------
11+
12+
- [Read more about Firebase Cloud Messaging](https://developers.google.com/cloud-messaging/)
13+
14+
Building and Running the testapp
15+
--------------------------------
16+
### iOS
17+
- Link your iOS app to the Firebase libraries.
18+
- Get access to the Firebase SDK git repo via
19+
[git cookie](https://cpdc-eap.googlesource.com/new-password).
20+
- Get CocoaPods version 1 or later by running,
21+
22+
```
23+
$ sudo gem install CocoaPods --pre
24+
```
25+
- From the testapp directory, install the CocoaPods listed in the Podfile by
26+
running,
27+
```
28+
$ pod install
29+
```
30+
- Open the generated Xcode workspace (which now has the CocoaPods),
31+
32+
```
33+
$ open testapp.xcworkspace
34+
```
35+
- For further details please refer to the
36+
[general instructions for setting up an iOS app with Firebase](https://developers.google.com/firebase/docs/ios/setup).
37+
38+
- Register your iOS app with Firebase.
39+
- Create a new app on
40+
[developers.google.com](https://developers.google.com/mobile/add?platform=android&cntapi=messaging&cntapp=Cloud%20Messaging%20Test%20App&cntpkg=com.google.android.messaging.testapp)
41+
, and attach your iOS app to it.
42+
- For Messaging, you will need an App Store ID. Use something random such
43+
as 12345678."
44+
- You can use "com.google.ios.messaging.testapp" as the iOS Bundle ID
45+
while you're testing.
46+
- Add the GoogleService-Info.plist that you downloaded from Firebase
47+
console to the testapp root directory. This file identifies your iOS app
48+
to the Firebase backend.
49+
- Add the following frameworks from the Firebase C++ SDK to the project:
50+
- frameworks/ios/universal/firebase.framework
51+
- frameworks/ios/universal/firebase_messaging.framework
52+
- You will need to either,
53+
1. Check "Copy items if needed" when adding the frameworks, or
54+
2. Add the framework path in "Framework Search Paths"
55+
- e.g. If you downloaded the Firebase C++ SDK to
56+
`/Users/me/firebase_cpp_sdk`,
57+
then you would add the path
58+
`/Users/me/firebase_cpp_sdk/frameworks/ios/universal`.
59+
- To add the path, in XCode, select your project in the project
60+
navigator, then select your target in the main window.
61+
Select the "Build Settings" tab, and click "All" to see all
62+
the build settings. Scroll down to "Search Paths", and add
63+
your path to "Framework Search Paths".
64+
- You need a valid
65+
[APNs](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html)
66+
certificate. If you don't already have one, see
67+
[Provisioning APNs SSL Certificates.](https://developers.google.com/firebase/docs/cloud-messaging/ios/certs)
68+
- In XCode, build & run the sample on an iOS device or simulator.
69+
- The testapp has no user interface. The output of the app can be viewed
70+
via the console. In Xcode, select
71+
`View --> Debug Area --> Activate Console` from the menu.
72+
73+
### Android
74+
**Register your Android app with Firebase.**
75+
76+
- Create a new app on
77+
[developers.google.com](https://developers.google.com/mobile/add?platform=android&cntapi=messaging&cntapp=Cloud%20Messaging%20Test%20App&cntpkg=com.google.android.messaging.testapp)
78+
, and attach your Android app to it.
79+
- You can use "com.google.android.messaging.testapp" as the Package Name
80+
while you're testing.
81+
- To [generate a SHA1](https://developers.google.com/android/guides/client-auth)
82+
run this command (_Note: the default password is 'android'_):
83+
* Mac and Linux:
84+
85+
```
86+
keytool -exportcert -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore
87+
```
88+
* Windows:
89+
90+
```
91+
keytool -exportcert -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
92+
```
93+
- If keytool reports that you do not have a debug.keystore, you can
94+
[create one](http://developer.android.com/tools/publishing/app-signing.html#signing-manually)
95+
with:
96+
97+
```
98+
keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"
99+
```
100+
- Add the `google-services.json` file that you downloaded from Firebase
101+
console to the root directory of testapp. This file identifies your
102+
Android app to the Firebase backend.
103+
- For further details please refer to the
104+
[general instructions for setting up an Android app with Firebase](https://developers.google.com/firebase/docs/android/setup).
105+
106+
**Configure your SDK paths**
107+
108+
- Configure the location of the Firebase C++ SDK by setting the
109+
`firebase_cpp_sdk.dir` Gradle property to the SDK install directory.
110+
* Run this command in the project directory, and modify the path to match your
111+
local installation path:
112+
113+
```
114+
> echo "systemProp.firebase_cpp_sdk.dir=/User/$USER/firebase_cpp_sdk" >> gradle.properties
115+
```
116+
- Ensure the Android SDK and NDK locations are set in Android Studio.
117+
* From the Android Studio launch menu, go to
118+
`Configure/Project Defaults/Project Structure` and download the SDK and NDK
119+
if the locations are not yet set.
120+
* Android Studio will write these paths to `local.properties`.
121+
122+
**Build & Run**
123+
124+
- Open `build.gradle` in Android Studio.
125+
- From the Android Studio launch menu, "Open an existing Android Studio
126+
project", and select `build.gradle`.
127+
- Install the SDK Platforms that Android Studio reports missing.
128+
- Build the testapp and run it on an Android device or emulator.
129+
- See [below](#using_the_test_app) for usage instructions.
130+
131+
Using the Test App
132+
------------------
133+
134+
- Install and run the test app on your iOS or Android device or emulator.
135+
- The application has minimal user interface. The output of the app can be
136+
viewed via the console:
137+
* **iOS**: Open select "View --> Debug Area --> Activate Console" from the
138+
menu in Xcode.
139+
* **Android**: View the logcat output in Android studio or by running
140+
"adb logcat" from the command line.
141+
- When you first run the app, it will print:
142+
`Recieved Registration Token: <code>`. Copy this code to a text editor.
143+
- Copy the ServerKey from the firebase console:
144+
- Open your project in the [firebase console](g.co/firebase)
145+
- Click `Notifications` in the menu on the left
146+
- Select the `Credentials` tab.
147+
- Copy the `Server Key`
148+
- Replace `<Server Key>` and `<Registration Token>` in this command and run it
149+
from the command line.
150+
```
151+
curl --header "Authorization: key=<Server Key>" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d '{"notification":{"title":"Hi","body":"Hello from the Cloud"},"data":{"score":"lots"},"to":"<Registration Token>"}'
152+
```
153+
- Observe the command received in the app, via the console output.
154+
155+
Support
156+
-------
157+
158+
[https://developers.google.com/firebase/support/]()
159+
160+
License
161+
-------
162+
163+
Copyright 2016 Google, Inc.
164+
165+
Licensed to the Apache Software Foundation (ASF) under one or more contributor
166+
license agreements. See the NOTICE file distributed with this work for
167+
additional information regarding copyright ownership. The ASF licenses this
168+
file to you under the Apache License, Version 2.0 (the "License"); you may not
169+
use this file except in compliance with the License. You may obtain a copy of
170+
the License at
171+
172+
http://www.apache.org/licenses/LICENSE-2.0
173+
174+
Unless required by applicable law or agreed to in writing, software
175+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
176+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
177+
License for the specific language governing permissions and limitations under
178+
the License.
179+

0 commit comments

Comments
 (0)