我正在尝试使用沙盒应用程序中的脚本桥从 iTunes 中过滤出一系列曲目。当应用程序不是沙盒时,以下工作有效,但在沙盒时无效:
if(!self.iTunes){
self.iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
self.library = [[[[self.iTunes sources] get] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"kind == %i", iTunesESrcLibrary]] objectAtIndex:0];
iTunesLibraryPlaylist *libraryPlaylist = [[[[self.library playlists] get] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"specialKind == %i", iTunesESpKMusic]] objectAtIndex:0];
self.musicTracks = [libraryPlaylist tracks];
}
// Create the playlist in iTunes
NSString *playlistName = selectedEquation.name;
iTunesPlaylist *playlist = [[[self.iTunes classForScriptingClass:@"playlist"] alloc] init];
[[self.library userPlaylists] insertObject:playlist atIndex:0];
[playlist setName:playlistName];
// Use persistent id to match between iTunesLibrary and ScriptingBridge
NSArray* iDArray = [self.tableTracks valueForKey:@"persistentID"];
for (NSNumber *decID in iDArray){
NSString* hexID = [NSString stringWithFormat:@"%llx", (long long)[decID integerValue]];
hexID = [hexID uppercaseString];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"persistentID", hexID];
[[[self.musicTracks filteredArrayUsingPredicate:predicate] objectAtIndex:0] duplicateTo:playlist];
}
这是一个错误,还是我错过了什么?如果我在运行过滤器之前转换self.musicTracks
为一个,它将起作用。NSArray
然而,这大大减慢了速度,以至于它实际上不可用。
编辑:这是我的权利文件。我绝对可以向它们添加播放列表和曲目——只是过滤不再起作用。
<?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.assets.music.read-write</key>
<true/>
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.iTunes</key>
<array>
<string>com.apple.iTunes.library.read-write</string>
</array>
</dict>
</dict>
</plist>