0

问题

虽然 Catalyst/iOS 应用程序可以正确处理可变推送通知,但它的表亲 macOS 应用程序不会在其通知服务扩展中执行方法来在呈现之前改变通知内容(当应用程序处于活动状态、后台或终止时)。

观察

控制台日志(如下)显示 Mac 扩展已找到并启动,但随后因“启动缓慢”而被终止。它是具有零依赖关系的普通新文件存根。我怀疑这是否重要,但我在 M1 上运行 Monterey RC1/Xcode 13 RC。

问题

我配置不正确是什么?

客观的

推送远程通知以下载文件,在本地处理用户数据,然后相应地静音或显示修改后的警报。

我试过了

每个未使用的 macOS 通知服务扩展

  • 确保沙盒化
  • 启用“传入连接(服务器)”(没有区别)
  • 擦除派生数据
  • 在天真的第二台 Mac 上运行

每个通知服务扩展不工作

  • 重新启动 Mac
  • 确保应用程序和扩展程序的部署目标相同

======================================

收到通知

应用程序(_应用程序:NSApplication,didReceiveRemoteNotification userInfo:[String:Any])

["customThing": value, "aps": {
    alert = "Push Mutable";
    "mutable-content" = 1;
    sound = default;
}]

功能截图

Mac 应用 在此处输入图像描述 通知扩展 在此处输入图像描述

扩展通知服务

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

        if let bestAttemptContent = bestAttemptContent {
            bestAttemptContent.title = "[modified]"
            bestAttemptContent.body = "Changed"
            contentHandler(bestAttemptContent)
        }
    }

    override func serviceExtensionTimeWillExpire() {
        if let contentHandler = contentHandler, let bestAttemptContent =  bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
    }
}

控制台输出

也许相关?

usernoted <IDENTIFIER> Extension will be killed due to sluggish startup error   serviceExt  com.apple.unc   usernoted

从构建到消息接收的完整日志(太长,无法在此处发布)。

PushNotifications   13:52:36.416625-0700    Found LSExtensionPoint <private> for identifier com.apple.usernotifications.service debug   default com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.416908-0700    Getting plist hint for data 0x14bf09020 debug   default com.apple.launchservices    LaunchServices
kernel  13:52:36.418499-0700    memorystatus: assertion priority 4 overrides priority 3 for PushNotifications:87796 default <Missing Description>       kernel
PushNotifications   13:52:36.417251-0700    Bootstrapping; checking if default NSViewService_PKSubsystem is needed by _AdditionalSubServices[viewbridge] dictionary entry: 0    debug   subsystems  com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.417444-0700    Bootstrapping; external subsystem [UIKit_PKSubsystem] initializing  info    subsystems  com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.417659-0700    Bootstrapping; external subsystem UIKit_PKSubsystem refused setup   error   subsystems  com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.417908-0700    Bootstrapping; Bootstrap complete. Ready for handshake from host.   default lifecycle   com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.422441-0700    <private>: will be managed by runningboard  info    lifecycle   com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.422555-0700    [u 91D39227-FB0E-4B7A-905E-F0B6FD44541A] [(null)((null))] Prepare received as euid = 501, uid = 501, personaid = 1001, type = DEFAULT, name = <private> default lifecycle   com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.422780-0700    Invoking selector platformWithContext:tableID:unitID:unitBytes: on <LSExtensionPointRecord 0x14be106e0> to get the value for property platform  debug   record  com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.422836-0700    Invoking selector identifierWithContext:tableID:unitID:unitBytes: on <LSExtensionPointRecord 0x14be106e0> to get the value for property identifier  debug   record  com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.422869-0700    Invoking selector nameWithContext:tableID:unitID:unitBytes: on <LSExtensionPointRecord 0x14be106e0> to get the value for property name  debug   record  com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.422899-0700    Invoking selector versionWithContext:tableID:unitID:unitBytes: on <LSExtensionPointRecord 0x14be106e0> to get the value for property version    debug   record  com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.422934-0700    Invoking selector SDKDictionaryWithContext:tableID:unitID:unitBytes: on <LSExtensionPointRecord 0x14be106e0> to get the value for property SDKDictionary    debug   record  com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.422962-0700    Got plist data 0x14c90d250 for unit 12550 from database 0x14d811400 debug   default com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.422991-0700    Invoking selector _persistentIdentifierWithContext:tableID:unitID:unitBytes: on <LSExtensionPointRecord 0x14be106e0> to get the value for property persistentIdentifier debug   record  com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.423027-0700    Found LSExtensionPoint <private> for identifier com.apple.usernotifications.service debug   default com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.423207-0700    Getting plist hint for data 0x14c90d250 debug   default com.apple.launchservices    LaunchServices
PushNotifications   13:52:36.423641-0700    [u 91D39227-FB0E-4B7A-905E-F0B6FD44541A] [(null)((null))] Merged plugin dictionary; NSExtension = <private>, XPCService = <private> debug   discovery   com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.423784-0700    [u 91D39227-FB0E-4B7A-905E-F0B6FD44541A] [(null)((null))] info [CFBundleShortVersionString] => [<private>]  debug   ls  com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.424294-0700    [u D325A4C7-3102-45E8-B540-E6756244D226] [<private>(<private>)] Set sole personality.   default lifecycle   com.apple.PlugInKit PlugInKit
PushNotifications   13:52:36.424720-0700    setting new value <private> for key <private> in CFPrefsSource<0x14c808fa0> (Domain: Volatile, User: , ByHost: No, Container: , Contents Need Refresh: No)  debug   User Defaults   com.apple.defaults  CoreFoundation
PushNotifications   13:52:36.425101-0700    looked up value <private> for key AppleLanguages in CFPrefsSource<0x14c808fa0> (Domain: Volatile, User: , ByHost: No, Container: , Contents Need Refresh: No) via CFPrefsSearchListSource<0x14c808e20> (Domain: <MY_APP_IDENTIFIER>-Mac.PushNotifications, Container: (null))   debug   User Defaults   com.apple.defaults  CoreFoundation
PushNotifications   13:52:36.426769-0700    setting new value <private> for key <private> in CFPrefsSource<0x14c808c60> (Domain: Volatile, User: , ByHost: No, Container: , Contents Need Refresh: No)  debug   User Defaults   com.apple.defaults  CoreFoundation
kernel  13:52:36.427292-0700    memorystatus: assertion priority 4 overrides priority 0 for PushNotifications:87796 default <Missing Description>       kernel
PushNotifications   13:52:36.426810-0700    setting new value <private> for key <private> in CFPrefsSource<0x14c808c60> (Domain: Volatile, User: , ByHost: No, Container: , Contents Need Refresh: No)  debug   User Defaults   com.apple.defaults  CoreFoundation
PushNotifications   13:52:36.426868-0700    setting new value <private> for key <private> in CFPrefsSource<0x14c808c60> (Domain: Volatile, User: , ByHost: No, Container: , Contents Need Refresh: No)  debug   User Defaults   com.apple.defaults  CoreFoundation
kernel  13:52:36.427751-0700    memorystatus: assertion priority 4 overrides priority 3 for PushNotifications:87796 default <Missing Description>       kernel
PushNotifications   13:52:36.427824-0700    [u D325A4C7-3102-45E8-B540-E6756244D226] [<private>(<private>)] Begin using received as euid = 501, uid = 501, personaid = 1001, type = DEFAULT, name = <private>   default lifecycle   com.apple.PlugInKit PlugInKit
kernel  13:52:36.428426-0700    memorystatus: assertion priority 4 overrides priority 0 for PushNotifications:87796 default <Missing Description>       kernel
runningboardd   13:52:36.429153-0700    Acquiring assertion targeting [xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796] from originator [daemon<com.apple.usernoted(501)>:431] with description <RBSAssertionDescriptor| "com.apple.extension.session" ID:175-431-381007 target:87796 attributes:[
    <RBSLegacyAttribute| requestedReason:ViewService reason:ViewService flags:( AllowIdleSleep PreventTaskSuspend PreventTaskThrottleDown )>,
    <RBSAcquisitionCompletionAttribute| policy:AfterValidation>
    ]>  default assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.429251-0700    Assertion 175-431-381007 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796]) will be created as active  default assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.429347-0700    Adding assertion 175-431-381007 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796]) debug   assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.429344-0700    Incrementing suppression state to 3 for xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>  debug   monitor com.apple.runningboard  RunningBoard
runningboardd   13:52:36.430195-0700    xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)> is now targeted by 2 assertions  info    assertion   com.apple.runningboard  RunningBoard
kernel  13:52:36.432558-0700    memorystatus: assertion priority 4 overrides priority 3 for PushNotifications:87796 default <Missing Description>       kernel
runningboardd   13:52:36.430841-0700    Updating events for assertion: 175-431-381007 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796])   debug   assertion   com.apple.runningboard  RunningBoard
kernel  13:52:36.432665-0700    memorystatus: assertion priority 4 overrides priority 0 for PushNotifications:87796 default <Missing Description>       kernel
runningboardd   13:52:36.430897-0700    Decrementing suppression state to 2 for xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>  debug   monitor com.apple.runningboard  RunningBoard
runningboardd   13:52:36.431022-0700    Removing events for context: 175-431-381007 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796]) debug   assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.430874-0700    Finished acquiring assertion 175-431-381007 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796]) info    assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.431621-0700    Enqueueing events for assertion: 175-431-381007 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796]) debug   assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.434007-0700    Invalidating assertion 175-431-381004 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796]) from originator [daemon<com.apple.usernoted(501)>:431]    default assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.441114-0700    Decrementing suppression state to 1 for xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>  debug   monitor com.apple.runningboard  RunningBoard
runningboardd   13:52:36.441179-0700    Decrementing suppression state to 0 for xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>  debug   monitor com.apple.runningboard  RunningBoard
runningboardd   13:52:36.441214-0700    END suppressing state updates for xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>    debug   monitor com.apple.runningboard  RunningBoard
runningboardd   13:52:36.537749-0700    Updating events for assertion: 175-431-381004 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796])   debug   assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.537795-0700    Removing events for context: 175-431-381004 (target:[xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796]) debug   assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.539009-0700    Removing assertion 175-431-381004 on [xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796] debug   assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.539175-0700    > xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)> ['com.apple.extension.session'] [175-431-381007]   debug   assertion   com.apple.runningboard  RunningBoard
runningboardd   13:52:36.539635-0700    xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)> is now targeted by 1 assertions  info    assertion   com.apple.runningboard  RunningBoard
opendirectoryd  13:52:38.292165-0700    PID: 87796, Client: 'PushNotifications', exited with 0 session(s), 0 node(s) and 0 active request(s)    info    session com.apple.opendirectoryd    opendirectoryd
usernoted   13:52:38.291635-0700    [<MY_APP_IDENTIFIER>-Mac.PushNotifications] Extension will be killed due to sluggish startup    error   serviceExt  com.apple.unc   usernoted
runningboardd   13:52:38.293025-0700    [xpcservice<<MY_APP_IDENTIFIER>-Mac.PushNotifications([daemon<com.apple.usernoted(501)>:431])(501)>:87796] termination reported by launchd (2, 9, 9)    default general com.apple.runningboard  RunningBoard
4

0 回答 0