question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It is not working on iOS 11.2 or iPhoneX

See original GitHub issue

Config.xml

<plugin name="cordova-plugin-local-notification" spec="0.9.0-beta.2" />

Ionic info:

cli packages: (C:\Users\lok\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 7.0.1

local packages:

    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : none
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 25.2.5
    Node              : v6.10.0
    npm               : 3.10.10
    OS                : Windows 8.1

Environment Variables:

    ANDROID_HOME : C:\Program Files (x86)\Android\android-sdk

Misc:

    backend : pro

I have installed the plugins like so:

ionic cordova plugin add cordova-plugin-local-notification
npm install --save @ionic-native/local-notifications

Code:

app.component.ts

constructor(){
 this.platform.ready().then(() => {
    timer(60000, 60000).subscribe(val => {//schedule Notification
      const hours = moment().format("H");
      const minutes = moment().format("m");
      if (hours == '10' && minutes == '1') this.scheduleNotification();
        });
    this.localNotificationHandler();
 });
}

scheduleNotification() {
    forEach(this.authenticationProvider.member.projects, (project: Project) => {
      forEach(project.transactions, (transaction: Transaction) => {
        if (transaction.dueOn != null && moment(transaction.dueOn).format('YYYY-MM-DD') == moment().format('YYYY-MM-DD')) {
          const id = random(1, 1000);
          cordova.plugins.notification.local.schedule({
            id: id,
            title: 'Due Today',
            text: `Payment for ${transaction.category.name}: ${transaction.description} of ${Number(transaction.totalPrice).toLocaleString()} is due today.`,
            data: { transaction: transaction, project: project },
            trigger: { every: { hour: 10, minute: 1 } },
          });
        }
      });
    });
  }

  localNotificationHandler() {
    this.localNotifications.on('click', (notification, state) => {
      const data = notification.data;
      const transaction = data.transaction;
      const project = data.project;
      this.goToEditTransaction(transaction, project);
    });
  }

It is working fine on the same day if an app goes to background mode few hours (less than 4 hours) on android device. But it is not working on iOS 11.2 or iPhoneX. On the Android device itself, we cannot trigger the click event. If we clicked the notification It opens the app again with a splash screen and goes to the desired screen (i.e. Edit ) without relevant data. That is useless since we need data for the edit screen.Could you tell me how to solve these issues?

Same sort of issue: https://forum.ionicframework.com/t/ionic-local-notification-trigger-call-back-is-not-working-when-app-is-in-background-for-a-while/114925

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17

github_iconTop GitHub Comments

1reaction
rwillettcommented, Apr 1, 2018

Times do not work on the background on IOS. You cannot schedule a notification using a background timer as the moment the app goes in the background, the JavaScript timer stops.

The Xcode simulator does not emulate the real IOS OS and keeps background timers running.

As said before, strip your code back and start with something simple and work your way up to something complicated.

Rob

0reactions
YeisonVelez11commented, Dec 15, 2018

@ddralves @Sampath-Lokuge I am using IONIC 1 and I am having the same problem… I’m trying to generate local notifications in the background. they work on an iphone6 but on an iphone xr nothing happens. I’m testing them in a simulator.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solution to the 11.2 + iPhone X ba… | Apple Developer Forums
What Im trying right now are third party backup editing tools to see if I can trick the iPhone X into accepting a...
Read more >
Face ID not working on iPhone X after updating to iOS 11.2? A ...
The iPhone X instead shows an alert that says it is 'unable to activate Face ID on this iPhone'. Luckily, the fix seems...
Read more >
Control Center Not Working in iOS 11 on iPhone 8 ... - EaseUS
Method 2: Go to Settings > General > Shut Down and move the slider to turn off your iPhone/iPad completely. Then press and...
Read more >
The Most Common iOS 11 Problems, and How to Fix Them
Solution: Apple fixed this issue in iOS 11.2. 6. Get the latest version of iOS by going to Settings > General > Software...
Read more >
iPhone X keeps restarting IOS 11.2.2 jUST UPDATED - iFixit
Every 3 minutes the iPhone X keeps restarting after updating it to IOS 11.2.2. There is no way i didn't try from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found