2016-06-13 6 views
0

私はiOS開発を初めて利用しています!私はUILocalNotificationでアプリを作成しようとしました。ここに私がしたことがあります:applicationIconBadgeNumberが更新されていないか増加していません

func createLocalNotification(structure:Structure) { 

     let localNotification = UILocalNotification() 
     localNotification.category = "CATEGORY" 
     localNotification.alertBody = "\(structure.messageBody)" 
     localNotification.alertAction = "see" 
     localNotification.soundName = UILocalNotificationDefaultSoundName 
     localNotification.userInfo = ["uuid":structure.UUID] 
     localNotification.fireDate = structure.date 
     localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1 

     print(localNotification) 

     UIApplication.sharedApplication().scheduleLocalNotification(localNotification) 
} 

それはうまく動作します!問題の行はapplicationBadgeNumberです。これはpropertyのようです。しかし、アプリが非アクティブな状態では増加しません。そして、アプリケーションが起動します。Xcodeは次のようなエラーを表示します。

レンダリングされていないビューをスナップショットすると、空のスナップショットになります。画面の更新後にスナップショットまたはスナップショットを作成する前に、ビューが少なくとも1回レンダリングされていることを確認してください。

どういう意味ですか?何が悪いですか?ご協力いただきありがとうございます!

答えて

1

まだコメントするには十分な反復がありません。アプリケーションが実行されていないときにバッジ番号を動的に設定できる唯一の方法は、プッシュ通知です。サーバー側のアップデートを追跡する必要があります

アプリがバックグラウンドにある間は、ローカル通知でバッジ番号を動的に更新することはできません。プッシュ通知を使用する必要があります。

1

登録設定をSoundBadgeに設定しましたか?このような

何か:(this linkから取られた部分)

@IBAction func registerLocal(sender: AnyObject) { 
    let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) 
    UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) 
} 
関連する問題