LoginSignup
5
7

More than 5 years have passed since last update.

Swift版 Nifty Cloud Mobile Backendでアイコンに付くバッチをリセットする方法

Posted at

せっかくiOSアプリをSwiftで書けるようになったのに、Objective-Cのスニペットが多すぎる!
ということで、私が変換したSwiftコードを貼り付けていくシリーズです。

Xcode 7.1, Swift2.1で確認しています。

元ネタはこちら
バッジ数をリセットしたい #52
https://github.com/NIFTYCloud-mbaas/UserCommunity/issues/52

func updateBadgeNumber(number : Int) {
    if ( number < 1 ) {
        UIApplication.sharedApplication().applicationIconBadgeNumber = -1
    } else {
        UIApplication.sharedApplication().applicationIconBadgeNumber = number
    }

    let currentInstallation = NCMBInstallation.currentInstallation()
    if (currentInstallation.deviceToken == nil) {
        return
    }

    // installation class update
    currentInstallation.setObject(number, forKey: "badge")
    currentInstallation.saveInBackgroundWithBlock{(error) -> Void in
        if ((error == nil)) {
            print("updateBadgeNumber complete")
        } else {
            print("updateBadgeNumber error: \(error)")
        }
    }

}
5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7