使用 Scripting Bridge 更新 iTunes 曲目异常

Exception updating iTunes track using Scripting Bridge

我正在编写一个 Mac 应用程序来使用 iTunes 脚本桥更新我的 iTunes 资料库中的一些元数据,但是当我尝试写入对数据的更改时遇到了困难。

我在 Objective C 中创建了一个简单的测试应用程序来演示这个问题,方法是用一些静态文本覆盖当前曲目的评论字段。

我的代码是:

iTunesApplication *myiTunesApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];

myiTunesApp.currentTrack.comment = @"Overwriting track comment";

BOOL success = myiTunesApp.currentTrack.commitEditing;

确实 成功写入新评论但抛出以下异常:

2016-11-01 21:46:55.307 iTunesScriptingBridgeExample[11117:1091018] -[ITunesTrack commitEditing]: unrecognized selector sent to instance 0x60800004b040
2016-11-01 21:46:55.308 iTunesScriptingBridgeExample[11117:1091018] -[ITunesTrack commitEditing]: unrecognized selector sent to instance 0x60800004b040
2016-11-01 21:46:55.310 iTunesScriptingBridgeExample[11117:1091018] (
    0   CoreFoundation                      0x00007fff9a8ca4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff8f6e2f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff9a9341ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff9a83a571 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff9a83a0f8 _CF_forwarding_prep_0 + 120
    5   iTunesScriptingBridgeExample        0x00000001000012a5 -[ViewController btnClicked:] + 197
    6   libsystem_trace.dylib               0x00007fff89e9c07a _os_activity_initiate + 75
    7   AppKit                              0x00007fff8a9a2dbd -[NSApplication sendAction:to:from:] + 460
    8   AppKit                              0x00007fff8a9b4f12 -[NSControl sendAction:to:] + 86
    9   AppKit                              0x00007fff8a9b4e3c __26-[NSCell _sendActionFrom:]_block_invoke + 131
    10  libsystem_trace.dylib               0x00007fff89e9c07a _os_activity_initiate + 75
    11  AppKit                              0x00007fff8a9b4d99 -[NSCell _sendActionFrom:] + 144
    12  libsystem_trace.dylib               0x00007fff89e9c07a _os_activity_initiate + 75
    13  AppKit                              0x00007fff8a9b33be -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
    14  AppKit                              0x00007fff8a9fbf04 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
    15  AppKit                              0x00007fff8a9b1ae8 -[NSControl mouseDown:] + 669
    16  AppKit                              0x00007fff8af063c9 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
    17  AppKit                              0x00007fff8af073ad -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
    18  AppKit                              0x00007fff8a946539 -[NSWindow sendEvent:] + 517
    19  AppKit                              0x00007fff8a8c6a38 -[NSApplication sendEvent:] + 2540
    20  AppKit                              0x00007fff8a72ddf2 -[NSApplication run] + 796
    21  AppKit                              0x00007fff8a6f7368 NSApplicationMain + 1176
    22  iTunesScriptingBridgeExample        0x0000000100001322 main + 34
    23  libdyld.dylib                       0x00007fff8e6595ad start + 1
    24  ???                                 0x0000000000000003 0x0 + 3
)

谁能告诉我这里可能做错了什么?

亲切的问候:)

ITunesTrack 没有 属性 或 commitEditing 的实现。

commitEditingNSEditor 协议的一部分。

The NSEditor informal protocol is implemented by controllers and user interface elements. It provides a means for requesting that the receiver commit or discard any pending edits.

These methods are typically invoked on user interface elements by a controller. They can also be sent to a controller in response to a user’s attempt to save a document or quit an application.

NSController provides an implementation of this protocol, as do the Application Kit user interface elements that support binding.