徽章推送增量仅适用于xcode

时间:2014-12-02 17:15:36

标签: ios objective-c apple-push-notifications

徽章推送增量仅在我的设备在xcode中运行时才有效,但是当我拔下它时,它只接收带声音的推送通知,正确提醒,但增量徽章不会出现在应用程序图标中。 有人知道吗?

提前致谢。

2 个答案:

答案 0 :(得分:1)

抱歉,这是我的php脚本,它与我的终端osx一起运行。

$deviceToken = '3d51...';
$tokenIpad   = '3bf2a..';


// Put your private key's passphrase here: // Second pass wich has been created
$passphrase = '37...';

// Put your alert message here:
$message = 'Hello!';
$badge   = '1';

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body = array(
    'aps' => array(
        "content-available" => "1",
        "alert"             => $message,
        "badge"             => $badge,
        "sound"             => 'default'
    )   
 );

// Encode the payload as JSON
$payload = json_encode($body);

// Add device tokens
$tokens = array(
    $deviceToken,
    //$tokenIpad  
);

foreach ($tokens as $value) 
{
    $msg = chr(0) . pack('n', 32) . pack('H*', $value) . pack('n', strlen($payload)) .                $payload; 
  $result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered' . PHP_EOL;
}

 // Close the connection to the server
  fclose($fp);

答案 1 :(得分:0)

这是我在AppDelegate中的代码:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

{     NSLog(@“Test%@”,userInfo);

if (userInfo)
{
    if ([userInfo objectForKey:@"aps"]) {
        if([[userInfo objectForKey:@"aps"] objectForKey:@"badge"]) {

            NSInteger increment = [[[userInfo objectForKey:@"aps"] objectForKey: @"badge"] intValue];
            increment = application.applicationIconBadgeNumber + increment;
            application.applicationIconBadgeNumber = increment;
        }
    }
}
completionHandler(UIBackgroundFetchResultNewData);

} 再次感谢。