Cordova_Ionic_HelloPush is an example usage of Bluemix push Cordova plugin in Ionic platform.
- Cordova Latest version
- Ionic
- Android Studio
- Xcode
To install the Ionic platform follow this [doc](https://ionicframework.com/getting-started/)
## Creating Ionic App.To create an Ionic app follow the below steps,
- Open the terminal app and run the following command to create an app
ionic start {appname} {template}
For Example;
ionic start ExampleApp blank
- Go to your appname directory,
cd {appname}
For Example;
cd ExampleApp
- Add platforms
ionic platform add ios
ionic platform add android
- Add the bms-push plugin to the project
cordova plugin add bms-push
It will add `bms-push` and `bms-core` plugins to your app
-
Edit the
www/index.html
and add your code for initializing and registering for Bluemix Push notifications. For reference check Example App Index.html & Exaple app push.js -
Do the
cordova prepare
andcordova build
.
Note: You may get ios build fail and you can neglect it.
To run the Android application got to **platforms -> android** and open it in **Android Studio** . Do the build and run it. You can check the registrations details in the console.
For running the iOS application got to **platforms -> ios** and open **yourApp.xcworkspace** in the latest Xcode (8+)
Follow the steps to complete the building of iOS App,
-
Change the Bundle Identifier and Signing credentials
-
Go to the AppDelegate.m file and add the following snippets
Add the #import "yourApp-swift.h"
// Register device token with Bluemix Push Notification Service
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
[[CDVBMSPush sharedInstance] didRegisterForRemoteNotifications:deviceToken];
}
// Handle error when failed to register device token with APNs
- (void)application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
[[CDVBMSPush sharedInstance] didFailToRegisterForRemoteNotifications:error];
}
// Handle receiving a remote notification
-(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
[[CDVBMSPush sharedInstance] didReceiveRemoteNotification:userInfo];
}
// Register device token with Bluemix Push Notification Service
func application(application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
CDVBMSPush.sharedInstance().didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)
}
// Handle error when failed to register device token with APNs
func application(application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: NSErrorPointer) {
CDVBMSPush.sharedInstance().didReceiveRemoteNotificationWithNotification(error)
}
// Handle receiving a remote notification
func application(application: UIApplication,
didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: ) {
CDVBMSPush.sharedInstance().didReceiveRemoteNotificationWithNotification(userInfo)
}
// Handle receiving a remote notification on launch
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let remoteNotif = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? NSDictionary
if remoteNotif != nil {
CDVBMSPush.sharedInstance().didReceiveRemoteNotificationOnLaunchWithLaunchOptions(launchOptions)
}
}
You can follow the this README to setup bms-push.
-
You have to set the Swift Legacy to yes in your
application
and in thepod frameworks (BMSPush, BMSAnalytics, BMSAnalyticsAPI, BMSCore and BMSSecurity)
. -
Clean and build the application.
-
Run the application.
The ExampleApp is an ionic app using bluemix push notifcations cordova plugin.
-
Edit the www/js/push.js file with your
APPGUID
,ClientSecret
andApp Region
. Do theCordova Prepare
andCordova build
. -
To run the iOS app got to platforms -> ios open in Xcode , build and Run the app.
-
To run the android app got to platforms -> android open in Android Studio , build and Run the app.
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.