无法使用iTunes Scripting Bridge和Sandboxing搜索音乐

时间:2013-11-06 03:05:37

标签: objective-c xml cocoa appstore-sandbox

我正在使用iTunes Scripting Bridge在iTunes中搜索用户的音乐。不幸的是,当我启用App Sandbox并使用iTunes.h中的以下方法时:

(iTunesTrack *) searchFor:(NSString *)for_ only:(iTunesESrA)only; 

它只返回零。但是,如果我禁用App Sandboxing,它的工作原理非常好。我似乎无法弄清楚我需要在权利文件中包含哪些权利才能使其正常工作。有什么想法吗?

我的代码:

SBElementArray *iTunesSources = [self.iTunes sources];
iTunesSource *library;
for (iTunesSource *thisSource in iTunesSources) {
    if ([thisSource kind] == iTunesESrcLibrary) {
        library = thisSource;
        break;
    }
}
SBElementArray *libraryPlaylists = [library libraryPlaylists];
iTunesLibraryPlaylist *libraryPlaylist = [libraryPlaylists objectAtIndex:0];

SBElementArray* searchTracks = (SBElementArray *)[libraryPlaylist searchFor:searchTerm only:iTunesESrAAll];

我的App.entitlements文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.app-sandbox</key>
    <true/>
    <key>com.apple.security.scripting-targets</key>
    <dict>
        <key>com.apple.iTunes</key>
        <array>
            <string>com.apple.iTunes.library.read-write</string>
            <string>com.apple.iTunes.playback</string>
            <string>com.apple.iTunes.playerInfo</string>
        </array>
    </dict>
</dict>

1 个答案:

答案 0 :(得分:2)

查看控制台并检查记录的沙箱违规类型;然后添加适当的权利。

如果是“因为它无权向此进程发送AppleEvent”。将此添加到权利文件:

<key>com.apple.security.temporary-exception.apple-events</key> <array> <key>com.apple.iTunes</key> </array>