iOS:Badge拒绝更新(appcelerator)

iOS:Badge拒绝更新(appcelerator),ios,push-notification,titanium,appcelerator,badge,Ios,Push Notification,Titanium,Appcelerator,Badge,我开发了一个应用程序,除了在应用程序未运行时更新徽章外,其他一切都正常运行 我收到推送通知,但徽章未发生任何变化 应用程序在向Apple注册时请求警报和徽章类型 有什么想法吗?这让我快发疯了 这是我用来发送推送的代码: <?php $apnsHost = 'gateway.sandbox.push.apple.com'; $apnsCert = '/usr/local/php/cert.pem'; $apnsPort = 2195; $streamContext = stream_con

我开发了一个应用程序,除了在应用程序未运行时更新徽章外,其他一切都正常运行

我收到推送通知,但徽章未发生任何变化

应用程序在向Apple注册时请求警报和徽章类型

有什么想法吗?这让我快发疯了

这是我用来发送推送的代码:

<?php
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsCert = '/usr/local/php/cert.pem';
$apnsPort = 2195;

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

$payload['aps'] = array('alert' => 'Oh hai!', 'badge' => 1);
$output = json_encode($payload);
$token = '1234';
$token = pack('H*', str_replace(' ', '', $token));
$apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) . $output;
fwrite($apns, $apnsMessage);

socket_close($apns);
fclose($apns);

您应该看看以下内容


  • 下面是一个使用push和app badge的示例,但正如我已经说过的,如果不能解决您的问题,您也必须向我显示您的移动端代码。下面是代码

        Titanium.Network.registerForPushNotifications({  
       types: [  
         Titanium.Network.NOTIFICATION_TYPE_BADGE,  
         Titanium.Network.NOTIFICATION_TYPE_ALERT  
       ],  
       success:function(e)  
       {  
         var deviceToken = e.deviceToken;  
         Ti.API.info("Push notification device token is: "+deviceToken);  
         alert('device token is' +e.deviceToken);  
         Ti.API.info("Push notification types: "+Titanium.Network.remoteNotificationTypes);  
         Ti.API.info("Push notification enabled: "+Titanium.Network.remoteNotificationsEnabled);  
       },  
       error:function(e)  
       {  
         Ti.API.info("Error during registration: "+e.error);  
       },  
       callback:function(e)  
       {  
         // called when a push notification is received.  
        //Titanium.Media.vibrate();  
        var data = JSON.parse(e.data);  
        var badge = data.badge;  
        if(badge > 0){  
         Titanium.UI.iPhone.appBadge = badge;  
        }  
        var message = data.message;  
        if(message != ''){  
         var my_alert = Ti.UI.createAlertDialog({title:'', message:message});  
         my_alert.show();  
        }  
       }  
      });   
     } 
    

    谢谢

    你能给我们看一下手机端的代码吗?当应用程序关闭时,它是否真的运行任何代码?据我所知,当应用程序不运行时,操作系统应该处理徽章?不,它不运行代码,但它在回调函数中执行此操作。因此,如果是这样,那么源代码就无关紧要了?问题是,当应用程序未运行时,如何更新徽章?请看上面的示例,我正在回调函数中更新徽章。您应该以同样的方式更新徽章。我理解这一概念,但如果应用程序关闭且用户未单击通知,该代码是否会实际运行?