PeterStaev / nativescript-azure-mobile-apps

:cloud: NativeScript plugin for working with Microsoft Azure Mobile Apps services
Apache License 2.0
30 stars 10 forks source link

Unable to use plugin #19

Closed shivapersad closed 7 years ago

shivapersad commented 7 years ago

Hi,

I am trying to get Push Notifications set up in my application using Azure's Notification Hub. I have the code below implemented in my homepage.component.ts. Please note I have removed my senderID and Azure portal name. Also do I need to setup a Mobile App in Azure to obtain the Azure portal name? I am assuming that when the application loads and it attempts to create the MobileServiceClient it receives a null and crashes the application.

When the application loads I am presented with the screenshot attached. Any assistance you can give would be appreciated.


import { MobileServiceClient } from "nativescript-azure-mobile-apps/client";

let pushPlugin = require("nativescript-push-notifications"); let client: MobileServiceClient; var pushSettings = { // Android settings senderID: 'project number here', // Android: Required setting with the sender/project number notificationCallbackAndroid: function(message, pushNotificationObject) { // Android: Callback to invoke when a new push is received. alert(JSON.stringify(message)); },

    // iOS settings
    badge: true, // Enable setting badge through Push Notification
    sound: true, // Enable playing a sound
    alert: true, // Enable creating a alert

    // Callback to invoke, when a push is received on iOS
    notificationCallbackIOS: function(message) {
        alert(JSON.stringify(message));
    }
};

client = new MobileServiceClient("https://.azurewebsites.net");

pushPlugin.register(pushSettings, (data) => { if (pushPlugin.onMessageReceived) { pushPlugin.onMessageReceived(pushSettings.notificationCallbackAndroid); } client.push.register(data) .then(() => console.log("Azure Register OK!")) .catch((e) => console.log(e)); }, (e) => { console.log(e); });


PeterStaev commented 7 years ago

Hey @shivapersad , I do not see a screenshot. But yes, you need to create a mobile app and configure it for push notifications by adding your iOS cert and android api key. Without those you cannot use the plugin.

shivapersad commented 7 years ago

I created the mobile app and connected the Push service for the mobile app in Azure.

I am having different issues for iOS and Android. In iOS I am able to launch the application but when I send a push notification nothing is received on my iOS device. I am currently using the iOS Simulator on my Macbook to perform testing.

With respect to Android I have attached a logcat when the application launches. For Android I am presently using a physical Android device.

Thanks for any help you can give.

azure-push-logcat.txt

PeterStaev commented 7 years ago

You cannot test push notifications on iOS Sim. You must use a physical device.

For Android - seems where you initialize the azure client the context is not present. So i'm assuming you are initializing somewhere before application start. You must init the client once the app has been initialized and started.

shivapersad commented 7 years ago

@PeterStaev I got through with Android!!! Able to push notifications from Azure to my physical Android device. Presently, working on the iOS side. Thanks for your help thus far. I'll let you know if I get any issues with iOS.

shivapersad commented 7 years ago

@PeterStaev I was able to get iOS to work as well. Notifications are a bit confusing but got the hang of it for my development devices. Thanks for your help!!

Cambia86 commented 6 years ago

hi @PeterStaev , i have a nativescipt app that works with firebase, i try to add azure registration but after command tns plugin add nativescript-azure-mobile-apps On import import { MobileServiceClient } from "nativescript-azure-mobile-apps/client"; I've error message that tell me that module 'nativescript-azure-mobile-apps/client' non found

Plugin version 2.0.1 "nativescript-azure-mobile-apps": "~2.0.1",

Can you help me?

PeterStaev commented 6 years ago

@Cambia86 , there is a demo app in this repo so you can look at it for how to use the plugin. Also please do not post in 1 year old closed issues. Instead submit a new issue describing your problem.