2013-07-29 59 views
0

我開發了一個應用程序,一切正常,除非更新徽章當應用程序未運行iOS:徽章拒絕更新(編輯器)

我收到推送通知,但徽章沒有任何反應。

應用程序在向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); 
+0

您能告訴我們手機端的代碼嗎? –

回答

0

下面是使用push和應用徽章一個例子,但正如我已經說你要告訴我你的手機端代碼太如果它不能解決你的問題。這裏是代碼

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(); 
    } 
    } 
    }); 
} 

謝謝

+0

應用程序關閉時是否真的運行任何代碼?據我瞭解,操作系統應該在應用程序不運行時處理徽章? – grandnasty

+0

不,它不運行代碼,但它在回調函數中執行此操作 –

+0

因此,如果是這樣的話,那麼源代碼將無關緊要?問題是應用程序未運行時如何更新徽章? – grandnasty