2012-05-31 115 views

回答

0

如果通知到達,你的應用是不是就是前臺,OS處理通知。

您的通知可以有一個字段badge,這將使OS更新徽章。但是,這意味着服務器比發送通知必須知道哪個數字應該是徽章。

通知機構應該是這樣的:

{ 
    "aps" : { 
     "badge" : 9 
    } 
} 
0

繼承人我的解決方案。我需要在一個應用程序中實現同樣的功能。我有一個下載隊列,並希望使用徽章來顯示剩餘的下載量,並在後臺保持更新。基本上我的解決辦法是,每次下載一個完成我設置一個UILocalNotification用無聲的聲音時,並沒有消息文本。只需設置徽章..如下所示..

- (void)queRequestFinished:(ASIHTTPRequest *)request { 

    self.inResourceCount -= 1; // Deducted 1 from the total count of downloads in queue. 

    Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls != nil) { 

    UILocalNotification *notif = [[cls alloc] init]; 
    notif.fireDate = [NSDate date]; // Schedule notification for now. 
    notif.timeZone = [NSTimeZone defaultTimeZone]; 
    notif.soundName = @"silence.caf"; 
    notif.applicationIconBadgeNumber = inResourceCount; // Number you want displayed as Badge. 

    // This is where the magic happens, and actually changes your badge.  
    [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 

    [notif release]; 
    } 

} 

我想指出,我的scenrio可能與你的不同。我用ASIHTTPRequest庫,而中背景具有繼續下載的支持,以上queRequestFinished:調用該方法,即使在後臺。希望這有助於,如果它標記爲答案:)。

相關問題