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();
}
});
Related
I have been using Expo to develop a react-native app, The functionality I am currently trying to implement is to share a link with friends on platforms such as fb messenger/whatapp or even normal texts and when they click this link it will launch my app to a specific page using the parameters.
After extensive research online - I’ve come to a blocker, following expo’s documentation I defined a scheme for my app - when I press share everything works correctly a message is created and I’m able to share content but only as string.
I am using react-natives Share library to share to an app and I’m using Expo to provide me with the link.
Ideally my first goal is to get the app opening using the Expo Link before I explore further into adding more functionality to the link.
Share.share({
message: "Click Here to View More! " + Linking.makeUrl( ' ' , { postkey : "7a5d6w2x9d6s3a28d8d});
url: Linking.makeUrl( ' ' , { pkey : gkey });
title: 'This post is amazing',
})
.then((result) =>{
console.log(result)
if(result === 'dismissedAction'){
return
}
})
.catch((error) => console.log(error))
In the root of my app I have also defined the event handlers: App.js
_handleRedirect=(event)=> {
let {path,queryParams} = Linking.parse(event);
Alert.alert(`queryparams : ${event} path : ${path} `)
this.props.navigation.navigate("Post_Detail",{key:queryParams.postkey})
}
}
componentDidMount() {
let scheme = 'nxet'
Linking.getInitialURL()
.then(url => {
console.log("App.js getInitialURL Triggered")
// this.handleOpenURL({ url });
})
.catch(error => console.error(error));
Linking.addEventListener('url', ({url}) => this._handleRedirect(url));;
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOpenURL);
}
When I share the link to Whatsapp, Facebook Messenger or even just messages or notes it appears as myapplink://, I try to enter this into the browser and instead of asking me to open my app - it does a google search.
Please note I am attempting to have this working on Android Device and facing this issue
Is there something I am doing incorrectly?
Any help is much appreciated. Thanks.
You can not open external links, means other than http, https on Android. But you can on iOS. In order to be able to open your expo links, you need proper anchor tags on android. You can create html mails and give it a try, you will see it is gonna work on Android as well.
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?
1.Everything work fine before share, I shared to Facebook Messenger and click the social content, the redirect link is not the link that firebase generated. The link has become the dynamic domain mixed with the title and description.
2.I tried to copy only the generated firebase link and paste to Facebook Messenger, social content loaded, then by clicking the content it call the dynamic link correctly and launch the app.
const link = new firebase.links.DynamicLink('https://example.com/parameter' , 'abc123.app.goo.gl')
.android.setPackageName('com.example.android')
.ios.setBundleId('com.example.android')
.social.setTitle("Social Title")
.social.setImageUrl("http://exmaple.com/super.png")
.social.setDescriptionText("Description");
firebase.links().createShortDynamicLink(link, 'SHORT')
.then((url) => {
Share.share({
message: "Message Title",
url: url,
title: "Title"
}, {
// Android only:
dialogTitle: 'Super Share'
})
// ...
});
How to share with correct dynamic link not just copy and paste, consider the user behavior.
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?",
},
})
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.)