2016-10-21 7 views
0

を表示していない数:エラーがスローされないIOS10は:バッジは、私は私のアプリアイコンにバッジとして数を表示するには、次のコードを使用しています

func triggerNotification(iAmountToday: Int) { 
    UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) { (granted, error) in 
    if granted { 
     let content = UNMutableNotificationContent() 
     content.badge = iAmountToday 
     content.categoryIdentifier = "com.psv.localNotification" 
     let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: 1.0, repeats: false) 
     let request = UNNotificationRequest.init(identifier: "AmountTodayUpdate", content: content, trigger: trigger) 

     let center = UNUserNotificationCenter.currentNotificationCenter() 
     center.addNotificationRequest(request, withCompletionHandler: { (error) in 
     if (error != nil) { 
      print (error) 
     } 
     }) 
    } 
    } 
} 

ものの、バッジ、アプリのアイコンで示されることはありません。

私は間違っていますか?

乾杯

+0

これを試してみてください。 content.badge = iAmountTodayをNSNumberとしますか?また、iAmountTodayが値を持っているかどうかをチェックします。 – Wolverine

+0

こんにちは@Wolverine、私はこれを試みたが効果がありません。 iAmountTodayは少なくとも0です - それもチェックしました – AntonSack

+0

少なくとも1に設定してください – Wolverine

答えて

1

スウィフト3.0、iOSの10

あなたは交換する必要があります。

UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Badge, .Sound, .Alert]) { (granted, error) in 

をして:

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (success, error) in 

これは私のために働きました。

敬具 ファビオ

関連する問題