Lately, I have been adding push notifications capability on my app. I am using FCN plugin found on this link and I developing using Ionic 2 framework. The notifications get delivered but when I tap on it it just opens the homepage of the app, and not the inner page that I need.
I have used this code
declare var FCMPlugin;
#Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
horoscopePage:any = HoroscopeHomePage;
#ViewChild(Nav) nav: Nav;
**********************
FCMPlugin.onNotification(function(data){
if(data.wasTapped){
//Notification was received on device tray and tapped by the user.
if(data.topic =="horoskopi" && data.type=="list"){
console.log( JSON.stringify(data) );
this.nav.push(this.horoscopePage);
}
}else{
if(data.topic =="horoskopi" && data.type=="list"){
console.log( JSON.stringify(data) );
this.nav.push(this.horoscopePage);
}
}
});
});
Somehow this line of code this.nav.push(this.horoscopePage); doesn't do anything
When I use NavController instead it gives me this error:
MyApp_Host.html:1 ERROR Error: No provider for NavController!
at injectionError (core.es5.js:1231)
at noProviderError (core.es5.js:1269)
at ReflectiveInjector_._throwOrNull (core.es5.js:2770)
at ReflectiveInjector_._getByKeyDefault (core.es5.js:2809)
at ReflectiveInjector_._getByKey (core.es5.js:2741)
at ReflectiveInjector_.get (core.es5.js:2610)
at AppModuleInjector.NgModuleInjector.get (core.es5.js:3578)
at resolveDep (core.es5.js:11039)
at createClass (core.es5.js:10903)
at createDirectiveInstance (core.es5.js:10723)
You can add public navCtrl: NavController into constructor then change code as
this.navCtrl.push(this.horoscopePage);
Well after I took a look at the official documentation of Ionic, I found out that we can't use NavController in app.component.ts because you can't inject NavController because any components that are navigation controllers are children of the root component so they aren't available to be injected. For more click here.
The reason that I was unable to push a new Page inside FCM.onNotifications() functions was that it changed the scope of application. The solutions was simple: just use the arrow function:
FCMPlugin.onNotification(
(data)=>{
if(data.wasTapped){
//do something
}
else {
//do something
}
});
Related
I’m just starting with Forge and JIRA apps development, I need to open a ModalDialog when an issue changes its state to “Done” (either by dragging it to the Done column or by changing its status in the issue panel). I don’t know where to start, I tried clonning the jira-issue-activity-ui-kit starter but I don’t get where the modal should open, any ideas? Thanks
This is the code I've tried:
const DONE = 'Done';
export async function run(event, context) {
console.log('Hello World!', event, event.changelog.items);
// if the issue is solved (status changed to Done)
if (event.changelog.items.some(function changedToPreferredStatus(change) {
return statusChangedTo(change, DONE);
})) {
let description = event.issue.fields.summary;
// OPEN MODAL DIALOG HERE
}
}
function statusChangedTo(change, to) {
return change.field === 'status' && change.toString === to;
}
I have 3 screens
ScreenA,
ScreenB,
ScreenC
Routes
ScreenA->ScreenB, ScreenB-back->ScreenA
ScreenA->ScreenC, ScreenC-back->ScreenA
ScreenA->ScreenB->ScreenC
My question is regarding 3rd route, when user is on ScreenC and he/she pressed backbutton/backnavbarbutton ScreenA will be shown instead of Screen B
Environment
React Native Navigation version: 1.1.431
React Native version: 0.54.4
Platform(s) (iOS, Android, or both?): iOS
You can use the setOnNavigatorEvent or the addOnNavigatorEvent which will replace the existing navigator for custom handling of back button..
so in your constructor
class ScreenC extends Component {
constructor(props) {
super(props);
this.props.navigator.setOnNavigatorEvent(
this.onNavigatorEvent.bind(this)
);
}
...
onNavigatorEvent(event) {
switch (event.id) {
case 'backPress':
... what ever you want
}
}
... rest of your code
}
You can read more about them here
I am currently working on an Ionic 2 app which requires authentication each time the app moves into the background and resumes.
import { ModalController } from 'ionic-angular';
#Component({
selector: 'item-details',
templateUrl: 'item-details.html'
})
export class ItemDetailsPage {
private modalCtrl: ModalController) {
}
ionViewDidLoad() {
this.platform.resume.subscribe(() => {
let modal = this.modalCtrl.create(LoginModalPage, true);
modal.present();
});
}
The issue I am having is that when the app resumes, it is correctly detects that it has resumed but then gives the error:
EXCEPTION: Attempted to assign to readonly property
When I use web inspector attached to the simulator it seems to imply the modal is undefined but I am unsure why.
This is how you have created modal
let modal = this.modalCtrl.create(LoginModalPage, true);
But from docs, instance is created with create(component, data, opts) where data is an object. In your case it is a boolean. So you need to pass an object. Here is the doc
I really need some help, because I'm very new to iOS and Phonegap developing and all topics on my Xcode-warning I could find were about Objective-C.
As my app is mainly written with Cordova (Phonegap) these solutions aren't really helpful.
So, what is there to tell:
I have a simple start screen, where you can start a barcode-scanner. The result (which in the end is always an url) should be displayed in the inAppBrowser of cordova.
If I call the window.open() with "_self" it works, but then it is very difficult to get back to the startscreen, as far as I found out.
So I wanted to call the url with the inAppBrowser so there is a "Done" button, but Xcode screams:
"Warning: Attempt to present <CDVInAppBrowserViewController:
0x1ed97060> on <MainViewController: 0x1ed64730> while a presentation
is in progress!"
Here the JavaScript code where I'm calling the window.open() function...
app.initialize();
function demoScan() {
try {
var scanned = scan();
} catch (e) {
alert('scan failed');
}
}
function scan() {
var scanner = window.cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan( function (result) {
var ref = window.open(encodeURI(result.text),'_blank','location=yes');
},
function (error) {
("Scanning failed: " + error);
});
}
In the end, I only need a (simple) solution, to get back to the start page "index.html" when I'm on the Webpage the Barcode scanner is calling. If it is through the inAppBrowser or with a self-coded "back" button in the WebView, I really don't care.
Thanks in advance! :)
Okay, I found the answer. You have to set a timeout before calling the inAppBrowser:
setTimeout( function() {
var ref = window.open(encodeURI(result.text),'_blank','location=no');
}, 500);
Apparently iOS needs some time to end whatever it was doing, before it can start the inAppBrowser.
In Android it works without the timeout.
I'm facing a problem using this 2 PhoneGap plugins: "BarcodeScanner" & "ChildBrowser" (inside an iOS app, with XCode 4 & PhoneGap 2.0).
I've a button "Scan" on my app UI. When the user clic on this button, the barcode scanner is launched.
So, in the Success function of the barcode scanner callback, I need to open the recovered URL from the scan in a new Childbrowser window (inner the app).
But the new Childbrowser window is never been opened, while the console displays "Opening Url : http://fr.wikipedia.org/" (for example).
Here is my JS part of code:
$("#btnStartScan").click(function() {
var scanBarcode = window.plugins.barcodeScanner.scan(
function(result) {
if (!result.cancelled){
openUrl(result.text);
}
},
function(error) {
navigator.notification.alert("scanning failed: " + error);
});
});
function openUrl(url)
{
try {
var root = this;
var cb = window.plugins.childBrowser;
if(cb != null) {
cb.showWebPage(url);
}
else{
alert("childbrowser is null");
}
}
catch (err) {
alert(err);
}
}
And all works fine if I call my openURL() function inside a Confirm alert callback for example, like this:
if (!result.cancelled){
navigator.notification.confirm("Confirm?",
function (b) {
if (b === 1) {
openUrl(result.text);
}
},
'Test',
'Yes, No');
}
But I need to launch the ChildBrowser window directly after a scan, without any confirm alert etc.
Does anybody know how to solve this please?
I also have this same problem.
Solve it by set timeout.
var scanBarcode = window.plugins.barcodeScanner.scan(
function(result) {
if (!result.cancelled){
setTimeout(function(){ openUrl(result.text); },500);
}
},
function(error) {
navigator.notification.alert("scanning failed: " + error);
});
I'm running into the exact same problem.
My application also has another mechanism to show a webpage besides the barcode reader and when I do that action I can see that the barcode-related page HAD loaded, but it never was shown.
In ChildBrowserViewController.m, I'm looking at the last line of loadURL() which is webView.hidden = NO; and I'm thinking that the child browser is set visible after we barcode but something about the barcode reader window caused the child browser to get set to the wrong z-order, but I'm not familiar enough with the sdk to know how to test that or try to bring it to the front.
Hope this helps target a potential area.