Objective c 沙箱使用SBElementArray破坏NSPredicate

Objective c 沙箱使用SBElementArray破坏NSPredicate,objective-c,itunes,scripting-bridge,appstore-sandbox,Objective C,Itunes,Scripting Bridge,Appstore Sandbox,我试图在沙盒应用程序中使用脚本桥从iTunes中过滤出一系列曲目。当应用程序未被沙盒时,但当它处于沙盒状态时,以下功能不起作用: if(!self.iTunes){ self.iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"]; self.library = [[[[self.iTunes sources] get] filteredArrayUsingPredicate:[NS

我试图在沙盒应用程序中使用脚本桥从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>

com.apple.security.app-sandbox
com.apple.security.assets.music.read-write
com.apple.security.scripting-targets
com.apple.iTunes
com.apple.iTunes.library.read-write
看,这是一个解决办法

NSArray* sbIDs = [self.musicTracks arrayByApplyingSelector:@selector(persistentID)];
// 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];
    // Persistent ID's have to have 16 characters in them.  Prepend zeros to make it so.
    while ([hexID length]<16) {
        hexID = [NSString stringWithFormat:@"%@%@", @"0", hexID];
    }
    NSInteger sbIndex = [sbIDs indexOfObject:hexID];
    [[self.musicTracks objectAtIndex:sbIndex] duplicateTo:playlist];
}
NSArray*sbIDs=[self.musicTracks arrayByApplyingSelector:@selector(persistentID)];
//使用持久id在iTunesLibrary和ScriptingBridge之间进行匹配
NSArray*iDArray=[self.tableTracks valueForKey:@“persistentID”];
用于(NSNumber*decID in iDArray){
NSString*hexID=[NSString stringWithFormat:@“%llx”,长)[decID integerValue]];
十六进制=[十六进制大写字符串];
//持久ID中必须包含16个字符。请在前面加上零。
而([六边形长度]看,这是一个解决办法

NSArray* sbIDs = [self.musicTracks arrayByApplyingSelector:@selector(persistentID)];
// 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];
    // Persistent ID's have to have 16 characters in them.  Prepend zeros to make it so.
    while ([hexID length]<16) {
        hexID = [NSString stringWithFormat:@"%@%@", @"0", hexID];
    }
    NSInteger sbIndex = [sbIDs indexOfObject:hexID];
    [[self.musicTracks objectAtIndex:sbIndex] duplicateTo:playlist];
}
NSArray*sbIDs=[self.musicTracks arrayByApplyingSelector:@selector(persistentID)];
//使用持久id在iTunesLibrary和ScriptingBridge之间进行匹配
NSArray*iDArray=[self.tableTracks valueForKey:@“persistentID”];
用于(NSNumber*decID in iDArray){
NSString*hexID=[NSString stringWithFormat:@“%llx”,长)[decID integerValue]];
十六进制=[十六进制大写字符串];
//持久ID中必须包含16个字符。请在前面加上零。

while([六边形长度]@t蓝色正确,观点正确。它被添加到问题中这也发生在我身上。看到这个问题:@t蓝色正确,观点正确。它被添加到问题中这也发生在我身上。看到这个问题:在未来,这个问题仍然存在,这个解决方法仍然有效。在未来,这个问题仍然存在,这个解决方法仍然有效。