程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-APNS 錯誤8 : Invalid token ,求解決

ios-APNS 錯誤8 : Invalid token ,求解決

編輯:編程綜合問答
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);
        }

最佳回答:


不知道有沒有人遇到過這種問題,度娘也不知道

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved