Giter Site home page Giter Site logo

cordova-plugin-azure-notificationhub's Introduction

Windows Azure Notification Hubs plugin for Apache Cordova

Exposes Windows Azure Notification Hubs functionality as Apache Cordova Plugin. Support of Windows8, Windows Phone8, iOS and Android.

Sample usage

var connectionString = "Endpoint=sb://[service bus name space].servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=[notification hub full key]",
    notificationHubPath = "[notification hub name]";

var hub = new WindowsAzure.Messaging.NotificationHub(notificationHubPath, connectionString);

hub.registerApplicationAsync().then(function (result) {
    console.log("Registration successful: " + result.registrationId);
});

hub.onPushNotificationReceived = function (msg) {
    console.log("Push Notification received: " + msg);
};;

Platform Quirks

iOS

On iOS the following code must be manually added to AppDelegate.m in order to have plugin to functional correctly.

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *) deviceToken
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidRegisterForRemoteNotifications" object:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidFailToRegisterForRemoteNotifications" object:error];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidReceiveRemoteNotification" object:userInfo];
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"UIApplicationDidRegisterUserNotificationSettings" object:notificationSettings];
}

Copyrights

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.

cordova-plugin-azure-notificationhub's People

Contributors

craigomatic avatar sgrebnov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cordova-plugin-azure-notificationhub's Issues

Question: How is didRegisterForRemoteNotificationsWithDeviceTokenCordova called?

Hi. I am new to iOS coding and although i can understand most of it, I can't quite figure out how didRegisterForRemoteNotificationsWithDeviceTokenCordova is called/invoked - this being the part that seems to do the actual registration with Notification Hubs after didRegisterForRemoteNotificationsWithDeviceToken. I can't find any reference to it and figure it is maybe some event that is thrown.

Any insight would be much appreciated.

Azure Notification Hub with Phonegap App

Hi, Im a newb to push notifications, but im looking for the best way to send xPlat push notification for phonegapp apps. I came across Microsofts Notification hub which "on paper" seems to serve all my needs.. I found this plugin in the Phonegap Build but i can't seem to get it to work.

Below is the code taken from the Usage Tutorial, but i can seem to get is to work, it doesnt report a thing! or maybe i don't know how debug effectively with the phonegap build, both ways, here you go:

//connection string and hub name not provided

 var hub = new WindowsAzure.Messaging.NotificationHub(notificationHubPath, connectionString);

       hub.registerApplicationAsync().then(function (result) {
           window.plugins.toast.show("Registration successful: " + result.registrationId, "long", "bottom", function (a) { console.log('toast success: ' + a) }, function (b) { alert('toast error: ' + b) });
       });

       hub.onPushNotificationReceived = function (msg) {
          alert("Push Notification received: " + msg);
       };

Has anyone had any luck getting Push notifications to work using PhoneGap and Azure?

PLEASE HELP!

Make unified object for onPushNotificationReceived callback

Make sure on all platforms push notification object passed to the onPushNotificationReceived callback is the same.

PushNotification:
type: 'toast' | 'tile' | 'badge' | 'custom' | ..
content: text1, text2, etc - parsed properties from notification received
raw: - raw string as it was received from the server side

Method registerApplicationAsync(tags) error "The certificate for this server is invalid..."

Hi there ! On iOS, Android and WP8, the method registerApplicationAsync(tags) end in the error callback with this message :

The certificate for this server is invalid. You might be connecting to a server that is pretending to be #######.servicebus.windows.net” which could put your confidential information at risk.

But Azure account for development is recent... And if I try with prod account, the result is the same. Do you have an idea ? Thanks a lot !!!
I'm on Cordova 5, the last version.

Android notifications does not received when app in the background

Currently application on Android does not receive notifications when it is not active. If I understand current design this is expected behavior. But I think that main use-case for push notifications is to notify user about application events when user outside of the app, where application could have different notification mechanisms.
I have to manually modify your plugin to use WakefulBroadcastReceiver and IntentService to be able have desired functionality.
When I implement I broke ability to handle notifications from JS part, since showing notification happens in the new IntentService which does not have CordovaWebView instantiated.

I see currently two way to improve current implementation.

  1. Add alternative implementation using WakefulBroadcastReceiver and IntentService and document how they could be enabled in the AndroidManifest.xml
  2. Instantiate CordovaWebView inside IntentService and load some limited subset of application inside that WebView. This is not very clear part for me and need discussion, but at least it could be starting point for discussion.

Not sure about iOS behavior, which I will check in next couple days and will post information for discussion.

I could provide patch with implementation which I have in my mind if needed.

Registration tags

When I was using the plugin with android, I realized that registration tags are not supported currently (method registerApplicationAsync(tags), in NotificationHub.js).
I really need this feature on my cordova project...
Do you know when we'll have an update to for this feature?

Kendo Listview fixed headers with WebSQL Storage???

Hi, ive been able to get the Kendo listview + WebSQL Datasource to work without issue for the most part. Problem is, when i try and add group options, the list refuses to build. i suspect im placing the code in the wrong section, but im not even sure kendo supports it. Anyone managed to get this to work?

heres my code for retrieving for webSQL datastore:

if (db) {
var dataSource = new kendo.data.DataSource.create({
transport: {
read: function (options) {

                       db.transaction(function (tx) {

                           tx.executeSql('SELECT * from Applications', [], function (tx, result) {

                               var data = [];
                               var custom = [];
                               // copy the rows to a regular array
                               for (var i = 0; i < result.rows.length; i++) {
                                   data[i] = result.rows.item(i);

                                   // create a new datasource with custom visual elements
                                   db.transaction(function (tx1) {


                                   });
                               }

                               options.success(data); // return the data back to the data source
                           });
                       });
                   }
               }, 


           });

           viewApplications(dataSource);

       }

AND FOR THE INITIALIZATION

function viewApplications(datasource) {
try{
$("#application-list").kendoMobileListView({
dataSource: datasource,
// group: "bizName",
pullToRefresh: false,
template: $("#application-template").html(),

            headerTemplate: "<h2>${bizName}</h2>",
            fixedHeaders: true,

            click: function (e) {
                $('.appOptions').show();
                $('#appOptions-add').hide();
                setListClick(e.dataItem.RefNo,e.dataItem.BizId,e.dataItem.ApplicantId);

            },
            create:function(e){
                console.log(e.dataItem.BizId);

            }


        });
    }
    catch (e) {
     alert(e);
    }

}

not working with ios

I installed the plugin and i have to provide gcm sender id to make it work in android. what is the eqivalent option that we have to provide for iOS

Missing required architecture on iOS

Hi!
I'm triying to use the plugin (using Visual Studio Cordova) and with android work well.
When I try to compile a debug version on iOS I have no problem (I cannot receive push but I think is for something else), if I try to compile a release version i Have this problem:

ignoring file MyApp/Plugins/msopentech.azure.NotificationHub/WindowsAzureMessaging.framework/WindowsAzureMessaging, missing required architecture arm64 in file MyApp/Plugins/msopentech.azure.NotificationHub/WindowsAzureMessaging.framework/WindowsAzureMessaging (3 slices)

Applications for platform ios can not be built on this OS - win32.

The following build commands failed:
1>      Ld build/MyApp.build/Release-iphoneos/MyApp.build/Objects-normal/arm64/MyApp normal arm64

How can I fix it?

Thanks

Phonegap Build

How to use this plugin with Phonegap Build?

Have you submitted this plugin to Phonegap.

Windows 8 fix on VS2015

Hi. Great library :-)

As outlined in my demo using this project a change is needed to make it work:

"There is an issue with this plugin as it stands with VS2015. You must change as follows. In plugins/msopentech.azure.NotificationHub/src/windows8/NotificationHubProxy.js, change

require("cordova/windows8/commandProxy").add("NotificationHub", module.exports);

to

require("cordova/exec/proxy").add("NotificationHub", module.exports);"

I would create a pull request for this but i only have VS2015 and Win 10 so not sure whether making a change would not be backwards compatible.

Improvement suggestion

You may remove the platform quirks for iOS if you use the same approach as in PushPlugin, i.e. extending AppDelegate by using a category + method swizzling.

I did it personally in my fork of your repository, from which I don't make a pull request to you only because we added some non-general purpose modification to the registration pattern, but it works!

This means no more need of modifying the AppDelegate.m manually, nor opening the bloody damned XCode to build your cordova project...! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.