我在向ios设备发送推送通知时收到errorNum:8

我在向ios设备发送推送通知时收到errorNum:8,第1张

概述var apn = require('apn');var gcm = require('android-gcm');export default function notification( devicetype, devicetoken, alert, userid, action, profilepic, image, youtubeimage, id ) { if
var apn = require('apn');var gcm = require('androID-gcm');export default function notification( devicetype,devicetoken,alert,userID,action,profilepic,image,youtubeimage,ID ) {       if(devicetoken != "(null)") {        var androIDAPIKey = '',cert = '',key = '',passphrase = '';        if(process.env.NODE_ENV.tolowerCase() == "production") {          cert = '/../config/ios_support/apns-cert.pem';          key = '/../config/ios_support/apns-key.pem';          passphrase = '*****';          androIDAPIKey = "*******";        }        else {          cert = '/../config/ios_support/apns-dev-cert.pem';          key = '/../config/ios_support/apns-dev-key.pem';          passphrase = '*******';          androIDAPIKey = "********";        }        if(devicetype == "ios"){            var myDevice = new apn.Device(devicetoken);            var note = new apn.Notification();            note.badge = 1;            note.sound = "notification-beep.wav";            note.alert = alert;            note.category = "respond"            note.device = myDevice;            note.payload = { 'action': action,'userID': userID,'profilepic': profilepic,'ID':ID};            console.log("note.payload: "+ JsON.stringify(note.payload));            //,'WatchKit Simulator Actions': [{"Title": "Show","IDentifIEr": "showbuttonAction"}]            var callback = function (errorNum,notification) {                console.log('Error is:.....',errorNum);            }            var options = {                gateway: 'gateway.push.apple.com',//'gateway.sandBox.push.apple.com',// this URL is different for Apple's Production Servers and changes when you go to production                errorCallback: callback,cert: __dirname.split('src/')[0] + cert,key: __dirname.split('src/')[0] + key,passphrase: passphrase,port: ****,cacheLength: 100            }            var apnsConnection = new apn.Connection(options);            apnsConnection.sendNotification(note);        }        else if(devicetype == "androID"){            var gcmObject = new gcm.AndroIDGcm(androIDAPIKey);            var message = new gcm.Message({                registration_IDs: [devicetoken],data: {                    body: alert,action: action,userID: userID,profilepic: profilepic,ID: ID                }            });            gcmObject.send(message,function(err,response) {                if(err) console.error("error: "+err);        //        else    console.log("response: "+response);            });        }    }}

Here is my code. In console I’m getting all the stuff and device token is also fine. AndroID mobiles are getting notifications. But notifications are not sending to ios devices. I’m getting this error in console : Error is:…… 8.
One more thing is,for the same device I’m able to send the notification for other functionality with other code.
Really I’m pulling my hair out for this issue. And can’t understand what’s wrong with my code. Anyone please give solution for this.

解决方法 您使用的是旧版本.去年3月,苹果公司在推送API中改变了一些东西.
此外,你忘了设置你的主题,这是apn推送通知的mandetory

如果(devicetype ==“ios”)阻止,请尝试这样的事情

if(devicetype == "ios") {    var myDevice = new apn.Device(devicetoken);    var note = new apn.Notification();    note.badge = 1;    note.sound = "notification-beep.wav";    note.alert = alert;    note.category = "respond"    note.payload = {'action': action,'ID': ID};    //you missed this one i guess    note.topic = "<your-app-bundle-ID>";    console.log("note.payload: " + JsON.stringify(note.payload));    //,"IDentifIEr": "showbuttonAction"}]    var callback = function(errorNum,notification) {        console.log('Error is:.....',errorNum);    }    var options = {        token: {            key: __dirname.split('src/')[0] + cert,keyID: __dirname.split('src/')[0] + key,teamID: "developer-team-ID"        },production: false // for development    };    var apnProvIDer = new apn.ProvIDer(options);    apnProvIDer.send(note,myDevice).then( (result) => {        // see documentation for an explanation of result        console.log(result);    });}

你可以在这里找到文档apn

总结

以上是内存溢出为你收集整理的我在向ios设备发送推送通知时收到errorNum:8全部内容,希望文章能够帮你解决我在向ios设备发送推送通知时收到errorNum:8所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1103145.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存