0

iOS デバイス間で音楽を送受信できるように設定しましたが、音楽が送信されるたびに、受信側の電話で次のエラーが発生します。

*** キャッチされない例外 'MPMediaItemCollectionInitException' が原因でアプリを終了します。理由: 'items array must not be empty' *** 最初にコール スタックをスローします:

これは、エラーが発生するメソッドです。

-(void)didReceiveDataWithNotification: (NSNotification *)notification{
    MCPeerID *peerID = [[notification userInfo] objectForKey:@"peerID"];
    NSString *peerDisplayName = peerID.displayName;
    NSData *receivedData = [[notification userInfo] objectForKey:@"data"];
    //NSLog([[notification userInfo] objectForKey:@"data"]);
    NSDictionary *dict = (NSDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:receivedData];
    NSString *datatype = [dict objectForKey:@"datatype"];
    NSLog(@"hi");
    if([datatype isEqualToString:@"musiclist"]){
        count++;
        MPMediaItemCollection *collectionFromPeer = [[MPMediaItemCollection alloc] initWithItems:[(MPMediaItemCollection*)[dict objectForKey:@"data"] items]];
        [_listOfMusic addObjectsFromArray:[collectionFromPeer items]];
        if(count == [[_appDelegate.mcManager.session connectedPeers] count] + 1){
            for(int i=0;i<[_listOfMusic count];i++){
                int r1 = arc4random() % [_listOfMusic count];
                int r2 = arc4random() % [_listOfMusic count];
                [_listOfMusic exchangeObjectAtIndex:r1 withObjectAtIndex:r2];
            }
            MPMediaItemCollection *coll = [[MPMediaItemCollection alloc]initWithItems:_listOfMusic];
            [_musicPlayer setQueueWithItemCollection:coll];
            NSLog(@"hi3");
            [_musicPlayer play];
        }
    }
}

何が問題なのか、またはこのエラーの原因は何ですか?

4

1 に答える 1