_玖-幽 2014-12-22 11:14 采纳率: 100%
浏览 8895
已采纳

APNS 错误8 : Invalid token ,求解决

用c#写的ios消息推送,引用PushSharp.Apple和PushSharp.Core 运行时出现下面错误:
APNS NotificationFailureException -> 8 : Invalid token

网上有说是token 64位的问题,http://www.cocoachina.com/bbs/read.php?tid=165961 不知道要怎么转成32位的?

还有.ForDeviceToken(tokenID)方法吧token改成32位 提示 5 : Invalid token size

求高手指点一下


 private void Form1_Load(object sender, EventArgs e)
        {  
            string token =  "8d6c30144e7a93e73cc1fafb0a5000000001a0a0bd1f66c9e0ab857291d00000"; 
           StarServices("production_identity.p12", "123123");
           SendSingleMess(token, "这是通过APNS的推送消息");
         }
 public void StarServices(string keyPath, string keyWord)
        {
            try
            {
                      push.OnNotificationSent += NotificationSent;    
            push.OnNotificationFailed += NotificationFailed; 
            push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;  
            push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;    
            push.OnChannelException += ChannelException;    
            push.OnServiceException += ServiceException;   
            push.OnChannelCreated += ChannelCreated;  //
            push.OnChannelDestroyed += ChannelDestroyed;  //
                var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, keyPath));
                push.RegisterAppleService(new ApplePushChannelSettings(appleCert, keyWord));  
            }
            catch { }
        }
 public void StopServices()
        {
            try
            {
                push.StopAllServices();
            }
            catch { }
        }
        public void SendSingleMess(string tokenID, string  message)
        {
            try
            { 
                push.QueueNotification(new AppleNotification()
                                           .ForDeviceToken(tokenID)
                                           .WithAlert(message)
                                           .WithBadge(7)
                                           .WithSound("sound.caf"));  
                Console.ReadLine(); 
            }
            catch  (Exception e)
            {
                Console.WriteLine("error:" + e.Message);
            }
        }

        public void Test()
        {

        }
        static void DeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
        {
            //Currently this event will only ever happen for Android GCM
            Console.WriteLine("Device Registration Changed:  Old-> " + oldSubscriptionId + "  New-> " + newSubscriptionId + " -> " + notification);
        }

        static void NotificationSent(object sender, INotification notification)
        { 
            Console.WriteLine("Sent: " + sender + " -> " + notification);
        }

        static void NotificationFailed(object sender, INotification notification, Exception notificationFailureException)
        { 
            Console.WriteLine("Failure: " + sender + " -> " + notificationFailureException.ToString() + " -> " + notification);
        }

        static void ChannelException(object sender, IPushChannel channel, Exception exception)
        {
            Console.WriteLine("Channel Exception: " + sender + " -> " + exception);
        }

        static void ServiceException(object sender, Exception exception)
        {
            Console.WriteLine("Service Exception: " + sender + " -> " + exception);
        }

        static void DeviceSubscriptionExpired(object sender, string expiredDeviceSubscriptionId, DateTime timestamp, INotification notification)
        {
            Console.WriteLine("Device Subscription Expired: " + sender + " -> " + expiredDeviceSubscriptionId);
        }

        static void ChannelDestroyed(object sender)
        {
            Console.WriteLine("Channel Destroyed for: " + sender);
        }

        static void ChannelCreated(object sender, IPushChannel pushChannel)
        {
            Console.WriteLine("Channel Created for: " + sender);
        }

  • 写回答

2条回答 默认 最新

  • _玖-幽 2014-12-23 01:21
    关注

    不知道有没有人遇到过这种问题,度娘也不知道

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动