Copyright 2013 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This sample application is not an official Google product.
This sample source code and project is designed to work with XCode 4.6. The resulted application is tested on iOS 6.1 and iPhone 5.
This iOS client is designed to work with Mobile Backend Starter backend.
Download this sample code from Google Cloud Platform Github.
This section provides a step-by-step guide so you can get the sample up and running in Xcode.
-
Download and install Xcode 4.6 on your Mac computer if you don't have it installed.
-
Download the Mobile Backend Starter backend.
-
You have a valid SSL certiciate that is APNS enabled (for the Java backend), a corresponding Provisioning Profile installed on your Mac computer. Otherwise, please follow the Apple documentation to obtain them.
If you do have a push notification certificate installed prior on your machine. You can follow these steps to export the *.p12 file for step 5 below:
- Open KeyChain Access
- Browse
My Certificates
under category on the left - Expand the
push certificate
- Select both the push certificate and key
- Right click and choose to export 2 items
- Set a password on the certificate
-
Follow the Mobile Backend Starter README.md and deploy the Mobile Backend Starter to App Engine.
-
Navigate to the Mobile Backend Starter configuration page i.e. https://your_app_id.appspot.com/admin/configure.jsp to register iOS Client ID by setting the Authentication/Authorization option to "Secured by Client IDs". Take a note of this Client ID which will be reentered on the iOS client side. Next, enable Google Cloud Messaging and iOS Push Notification and provide the
APNS Provider Certification Password
. At last, click Select APNS Certificate and Save to upload the *.p12 certificate and finally save the configuration. -
You have an iPhone, that is provisioned for development and runs iOS version 6.1.
- Open a new Finder window and navigate to the directory you extract the sample client code. Double click on the ClientBackendIOSClient.xcodeproj file. It will open the project in Xcode automatically.
- The iOS client application bundle ID has to match the one you used for creating the SSL certificate and the Provisioning Profile. Out-of-the-box bundle ID is
com.google.CloudPushSample.dev
. Please rename the bundle ID accordingly via project TARGETS in Xcode.
- Fill in the kCloudBackendClientID and kCloudBackendClientSecret values in Constants.m. The kCloudBackendClientID has to match with the Client ID you used in the backend as described in step 5 of the Prerequisite. The kCloudBackendClientSecret is the matching client secret for the Client ID from API Console.
- Replace {{{ INSERT APP ID }}} in the kCloudBackendServiceURL variable in Constants.m with the App Engine Application id where the Mobile Backend Starter is deployed to.
- Click on the project in the Ffile Browser panel
- Click on the project in the Settings browser
- Click on the Build Settings tab
- Browse down to Code Signing Identity
- Select a valid code signing certificate (APNS enabled provisioning profile)
- On the top left corner of the toolbar, select
[Your bundle ID] > iOS Device
. Then click theRun
button to execute the application. - The application should open up in your iPhone.
- If this is the first time the CloudBackendIOSClient app executes, a Google login page may show up asking for your credential and your consent to identify your account. Go ahead and sign in.
- Click on the the "+" sign on the top right corner and enter a message. Hit return will save the input.
- The Guestbook should refresh and show the latest message. You can also use the pull down gesture to refresh the list manually. Note that each time when there is a new message or update sent to the backend, this application will be notified by push notification which triggers this application to query against the backend. You can test this by entering a new message and immediately hitting the home key to navigate away from this application. Within seconds, you will receive a push notification alerting you that a message is received. When you navigate back to the application, you will see the latest message being queried and displayed.
- Repeat step 2 a few times. You should see a list of messages displayed in reverse chronological order.
- If you have a few Android or iOS devices, register them to the same Mobile Backend Starter backend, you can then use this application to communicate among multiple devices.
- Open any browser and navigate to the Mobile Backend Starter configuration page. In the Send Cloud Message section, click Send. Your phone will then receive a push notification which alerts the Guestbook to display an alert. This alert will display the broadcast message as specified and dismiss automatically based on the duration value.