How to launch different screen of apple watch app from different notification? - push-notification

Problem:
How to launch different screen of apple watch app from different notification?
This is my setup:
I have 2 static WKUserNotificationInterfaceController:
1) awardsCategory
2) otherCategories
This is my PushNotificationPayload.apns file for "awardsCategory" notification:
{
"aps": {
"alert": {
"body": "Hello world!",
"title": "Optional title"
},
"category": "salaryCategory"
},
"WatchKit Simulator Actions": [
{
"title": "Details",
"identifier": "detailsButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}
Once I received a notification, pressing the notification sash or "Details" Button will launch the watch app:
How is it possible for the watch app to determined whether the notification is from awardsCategory or from otherCategories? And From there we can set our initial controller?

When the user taps a button on the notification, the main interface controller is always displayed. handleActionWithIdentifier:forRemoteNotification: is called on your main controller and you can update the UI there. For example, you could hide certain elements, or push a different controller.
(If the user taps on the sash, the identifier will be an empty string.)

Related

Can't get the `data-*-id` attribute to properly record the custom event name via ClickAnalytics plugin

I have a client React app I'm instrumenting in appinsights, and I'm using both the React plugin and the new ClickAnalytics plugin. Everything works, telemetry is flowing, however I'm having trouble getting the data-*-id custom event feature working properly.
The docs say:
The id provided in the data-*-id will be used as the customEvent name. For example, if the clicked HTML element has the attribute "data-sample-id"="button1", then "button1" will be the customEvent name.
I instrument an element as follows (using Semantic UI React):
<Button
data-custom-id="AddDealButton"
as={Link}
color="blue"
icon
labelPosition="right"
size="huge"
>
Clicking that button causes the custom event to record but the name, "AddDealButton", doesn't flow through. I always get not_specified as the event name:
Reading the docs, there is this warning regarding the plugin configuration:
If useDefaultContentNameOrId is false, then the customEvent name will be "not_specified".
So I am initializing the plugin this way:
...
extensions: [reactPlugin, clickPlugin],
extensionConfig: {
[reactPlugin.identifier]: { history: browserHistory },
[clickPlugin.identifier]: { autoCapture: true, useDefaultContentNameOrId: true }
}
...yet the name does not pass. Am I misconfiguring? Any idea what I'm doing wrong?
It turns out the problem was in the initialization configuration I showed above. It should be set up as follows:
...
extensions: [reactPlugin, clickPlugin],
extensionConfig: {
[reactPlugin.identifier]: { history: browserHistory },
[clickPlugin.identifier]: { autoCapture: true, dataTags: { useDefaultContentNameOrId: true } }
}
The resulting event name is not being pulled from my data-custom-id but rather pulled from the content of the Icon element of the Button component, so the event name becomes "Create new deal", but I can figure that out.
Microsoft's docs show a different samples for the npm install method vs the "snippet" method, and so I missed the dataTags sample.

How to know if firebase.messaging().requestPermission has been previously called using react-native-firebase

I have a React Native app that uses Firebase Cloud Messaging with the react-native-firebase package.
I am doing this on the first screen of a React Native app, so after 5 seconds, the user will be sent to a new screen which explains why push notifications are useful, and gives them a button to launch the dialog where they can accept or decline the permission.
setTimeout(() => {
firebase.messaging().hasPermission()
.then(enabled => {
if (enabled) {
// user has permissions
} else {
// user doesn't have permission
this.props.navigation.navigate('EnableNotificationPermissionScreen')
}
});
},
5000);
In the EnableNotificationPermissionScreen screen, there is a button like this:
<Button onPress={this.onSetNotificationPref.bind(this)} title="Set Notification Preference" color="#4ab2fc"/>
Which is handled by an event like this:
onSetNotificationPref() {
firebase.messaging().requestPermission()
.then(() => {
// User has authorized
firebase.analytics().logEvent('messaging_permission_accepted');
this.props.navigation.navigate('App');
})
.catch(error => {
// User has rejected permissions
firebase.analytics().logEvent('messaging_permission_rejected');
this.props.navigation.navigate('App');
});
}
If the user accepts, everything works as I would hope, and the user will have the permission, and will not navigate to that screen again.
However, if the user rejects the permission, I do not want to navigate them to that screen again. As-is, they will be navigated there again because hasPermission will be false. Also, clicking the button to execute requestPermission on that screen will do nothing, as the OS will block requestPermission().
In the examples I have seen, requestPermission is called whenever the permission is not enabled (with no custom screen like this); and so either the dialog pops up, or it doesn't. However, in the flow that I am trying to achieve, I want to navigate to this custom screen only if the user does not have permission because they have not been asked. If they have been asked and declined, they should not be navigated to that screen.
Is there any way to achieve that using the functions in firebase.messaging(), or do I have to use persistent storage like async-storage to track on my own whether the dialog has been shown?

Open differents pages ionic 3 with push notifications

I need help,
I am trying to open different pages of my application in ionic3, I can do it for a specific page, but I want to differentiate the type of notification, example if the notification is of the message type, my message page is opened and if it is another type of notification will open a different page.
pushObject.on('notification').subscribe((notification: any) => {
this.nav.push(PushNotification); //here open specific page, but I need to open not only a specific page but several pages.
if (notification.additionalData.foreground) {
let youralert = this.alertCtrl.create({
title: 'New Push notification',
message: notification.message,
});
youralert.present();
}
});

How do I send GCM that when clicked opens URL?

I have set up service workers that subscribe to notifications. When Chrome is in the foreground the javascript controls the notification content and its notificationclick event handler will open a web page when the notification is clicked. (code not shown)
But when Chrome is in the background, the "Notification" payload is used for the notification content instead (js not activated), and when I click the notification it just opens Chrome without opening any web page at all.
I can live with having to handle two cases (Chrome was foreground or it wasn't), but clicking on them need to open a web page in both cases.
I'm thinking either my notification is missing some parameter, or I need my js to listen to a service-worker event that is triggered when Chrome opens. But I can't find a list of events that would be relevant.
Code that sends notifications:
import (
gcm "github.com/google/go-gcm"
)
[...]
res, err := gcm.SendHttp(apiKey, gcm.HttpMessage{
// `destination` is the subscription endpoint provided by
// serviceWorkerRegistration.pushManager.subscribe callback.
RegistrationIds: []string{destination},
ContentAvailable: true,
TimeToLive: &ttl,
// This shows up when chrome is not open only. wut?
Notification: &gcm.Notification{
Title: `Title here`,
Body: "Blah blah lorem ipsum",
Sound: "default",
Color: "#ff0000",
//ClickAction: "something here?",
},
})

Share activity on Google Plus using asp dotnet

How can i post an interactive post on google+ stream?
I am trying to post some custom data on google stream from asp.net web application.
This is the code iam using.
this is .aspx page:
Tell your friends
this is the script i am using:
var moment = {
"name": "sample",
"Description": "Hi sample post",
"Thumbnail": "logo",
"image": "http://prayati.com/Images/PrayatiLogo.jpg"
};
gapi.auth.init(signinCallback);
function signinCallback(authResult) {
if (authResult['access_token']) {
gapi.interactivepost.render('inter', options);
//gapi.interactivepost.render(moment, authResult['access_token'])
gapi.interactivepost.go(moment)
document.getElementById('myBtn').setAttribute('style', 'display: none');
} else if (authResult['error']) {
alert(authResult['error']);
}
}
var options = {
contenturl: 'https://plus.google.com/pages/',
contentdeeplinkid: '/pages',
clientid: '263087742134.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
prefilltext: 'Create your Google+ Page too!',
calltoactionlabel: 'SHARE',
calltoactionurl: 'http://plus.google.com/pages/create',
calltoactiondeeplinkid: '/pages/create'
};
The first and probably most important problem is that you have a domain mismatch between your data-calltoactionurl and your data-contenturl. These must be the same domain, see the data-contenturl documentation.
I believe that is your major problem, there are other problems in your example too:
You appear to be confusing two different features: app activities (aka moments) and interactive posts. Also, it looks like you are trying to do authentication, the interactive post button is also a sign-in button, notice its data-callback parameter. You wouldn't need to do a separate call to gapi.auth.init()
The most simple approach is to use the HTML button and remove the calls to gapi.interactivepost.* unless you have a dynamic application that needs to insert buttons with great control.
You didn't post the code for your JavaScript API include, ensure that it is loading the API script as https://apis.google.com/js/client:plusone.js.
Here is a correct and simplified button:
<button class="g-interactivepost"
data-clientid="xxxxxxxxxx.apps.googleusercontent.com"
data-contenturl="http://localhost:52022/Jaswanth"
data-cookiepolicy="single_host_origin"
data-calltoactionlabel="INVITE"
data-calltoactionurl="http://localhost:52022/create"
data-prefilltext="Best site EVER!"
data-callback="signinCallback"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.login">
Tell your friends
</button>

Resources