2017-08-10 20 views
0

我試圖在用Ionic 3開發的應用程序中實現推送通知。我正在按照本教程進行操作:https://medium.com/@ankushaggarwal/generate-apns-certificate-for-ios-push-notifications-85e4a917d522爲什麼我的離子iOS應用程序沒有收到任何推送通知?

對於Android,我收到了通知。

但是,在iOS上,當我發送推送通知時,我在iOS上完全沒有任何功能。

我做了以下內容:

  • 得到一個APN推證書
  • 上傳它在我的離子帳戶
  • 切換在Xcode
  • 也是「推送通知」上的「功能」選項卡下在同一標籤下打開「背景模式/遠程通知」

我的代碼與在上面的教程:

initPushNotifications() { 
    if (!this.platform.is("cordova")) { 
     console.warn("Push notifications not initialized. Cordova is not available - Run in physical device"); 
     return; 
    } 

    const options: PushOptions = { 
     android: { 
      senderID: "784098698049" 
     }, 
     ios: { 
      alert: "true", 
      badge: false, 
      sound: "true" 
     }, 
     windows: {} 
    }; 

    const pushObject: PushObject = this.push.init(options); 

    pushObject 
    .on("registration") 
    .subscribe((data: any) => { 
     console.log("device token -> " + data.registrationId); 

     this.userService.edit({ 
      ionicToken: data.registrationId 
     }); 
    }); 

    pushObject.on("notification").subscribe((data: any) => { 
     console.log("message -> " + data.message); 
     //if user using app and push notification comes 
     if (data.additionalData.foreground) { 
      // if application open, show popup 
      let confirmAlert = this.alertCtrl.create({ 
       title: "New Notification", 
       message: data.message, 
       buttons: [{ 
        text: 'Ignore', 
        role: 'cancel' 
       }, { 
        text: 'View', 
        handler:() => { 
         //TODO: Your logic here 
        } 
       }] 
      }); 
      confirmAlert.present(); 
     } else { 
      //if user NOT using app and push notification comes 
      //TODO: Your logic on click of push notification directly 
      console.log('Push notification clicked'); 
     } 
    }); 

    pushObject.on('error').subscribe(error => console.error('Error with Push plugin' + error)); 
} 

我也試過官方文檔以下的https://docs.ionic.io/services/push/,不使用相同的模塊。不過,結果是一樣的:它可以在Android上運行,但不能在iOS上運行。

我不知道我是否可以在某處找到某些日誌,找出是否有錯誤。如果有人有關於此的信息,請分享。

有沒有人用Ionic實現推送通知?

謝謝。

回答

0

您需要通過Apple的testflight或App store運行您的應用程序。根據我的經驗,如果您只是在手機上本地運行應用程序,推送通知將不起作用。

相關問題