ionic-team / ionic-app-scripts

App Build Scripts for Ionic Projects
http://ionicframework.com/
MIT License
609 stars 300 forks source link

Click - Local Notifications #1473

Open AmineSkills opened 5 years ago

AmineSkills commented 5 years ago

Hi, i want to fix some errors.. thanks in advance.

I installed "Local Notifications" plugin in my app to send automatically notifications to users, it's good but i have some issues when i use simulator :

  1. When user have o more than 55 (nearly) of notifications, he can't receive any notification !
  2. The notification not stay a long (just 2 or 3 second i think).. can it stay at user see it if he don't use the phone that moment ?!
  3. My app icon doesn't appear, but is replaced by ionic icon.
  4. I want add a link in notification by click. So, when user click on notification, he will go automatically to an other page. This is my code but, it give me this error in execution : http://urlz.fr/7H4F
constructor(public navCtrl: NavController, public navParams: NavParams, private apiprovider: ApiProvider, public localNotifications:LocalNotifications, public platform: Platform, public alertCtrl:AlertController) {

    this.platform.ready().then(()=>{
      this.localNotifications.on('click',(notification,state) =>{ 
        let json = JSON.parse(notification.data);
        let alert = this.alertCtrl.create({
          title: json.mydataTitle,
          subTitle: json.mydataContent
          });
          alert.present();
         });
      });
  }

  ngOnInit()
  {
     this.iduser=this.navParams.get('iduser');
     this.apiprovider.getNotifs(this.iduser).subscribe(
      data => { this.notifications = data; 
          for(let elt of this.notifications)
            {
                this.localNotifications.schedule({
                   id: elt.id_not,
                   title: elt.title_not,
                   text: elt.content_not,
                   trigger: {at: new Date(new Date().getTime() + 1600)},
                   led: 'FF0000',
                   icon: '../../assets/imgs/logo.png',
                   sound: this.setSound(),
                   data: {mydataTitle:elt.titre_not,mydataContent:elt.contenu_not}
                });
            }
          },
      error => { console.log(error) }
    );
}

setSound()
  {
      if (this.platform.is('android')) 
      {
        return 'file://assets/sounds/Rooster.mp3';
      }
      else {
        return 'file://assets/sounds/Rooster.caf';
      }
  } 
afloresv11 commented 5 years ago

For the error Expected 1 but got 2: The Local Notifications plugin in the new version change the code implementation, now we should use subscribe

this.localNotifications.on("click").subscribe(notification => 
{
 console.log(notification);
});        
AmineSkills commented 5 years ago

That's right, thank you very much