Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通知バッヂ需要 #5

Open
fruitriin opened this issue Jun 14, 2023 · 1 comment
Open

通知バッヂ需要 #5

fruitriin opened this issue Jun 14, 2023 · 1 comment

Comments

@fruitriin
Copy link
Owner

fruitriin commented Jun 14, 2023

需要があるとかないとか(ないかも

┆Issue is synchronized with this Trello card by Unito

@fruitriin
Copy link
Owner Author

Mac OSでは、他のアプリケーションについている通知バッジの状況を取得することは可能です。Mac OSでは通知センターと呼ばれる機能があり、アプリケーションからの通知を一元管理するための機能です。

アプリケーションが通知センターに通知を送信すると、通知バッジが表示されます。そのため、特定のアプリケーションの通知バッジの状況を取得するには、通知センターから情報を取得する必要があります。

以下は、Swiftで通知センターから通知バッジの状況を取得する方法の例です:

import Foundation
import NotificationCenter

// 通知センターのインスタンスを取得
let notificationCenter = NSUserNotificationCenter.default

// 通知センターから通知の配列を取得
let deliveredNotifications = notificationCenter.deliveredNotifications

// 特定のアプリケーションの通知バッジの状況を取得する
for notification in deliveredNotifications {
    if notification.identifier == "your_app_identifier" {
        let badgeNumber = notification.applicationBadgeNumber
        print("通知バッジの数: \(badgeNumber)")
    }
}

このコードでは、deliveredNotificationsを使用して通知センターから配信された通知のリストを取得し、特定のアプリケーションの通知バッジの状況を取得しています。your_app_identifierの部分は、対象のアプリケーションのバンドル識別子に置き換えてください。

ただし、注意点として、ユーザーが通知を許可しているアプリケーションのみが通知センターに表示されます。許可されていないアプリケーションの通知バッジの状況を取得することはできません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@fruitriin and others