2014-01-13 143 views
0

您好我整合SpotifyLib CocoaLibSpotify iOS庫17-20-26-630到我的項目。我打開它SPLoginViewController使用波紋管方法: -Spotify EXC_BAD_EXE第二次點擊登錄按鈕後關閉LoginViewController

-(void)OpenSpotify 
{ 
    NSError *error = nil; 


    [SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size] 
               userAgent:@"com.mycomp.spotify" 
              loadingPolicy:SPAsyncLoadingImmediate 
                error:&error]; 
    if (error != nil) { 
     NSLog(@"CocoaLibSpotify init failed: %@", error); 
     abort(); 
    } 

    [[SPSession sharedSession] setDelegate:self]; 
    [self performSelector:@selector(showLogin) withObject:nil afterDelay:0.0]; 

} 

-(void)showLogin 
{ 
    SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]]; 
    controller.allowsCancel = YES; 
    //controller.view.frame=; 
    [self presentViewController:controller animated:YES completion:nil]; 
} 

,第一時間出現Spotify Login屏幕。之後,我點擊取消按鈕,並嘗試再次打開登錄屏幕,然後我崩潰EXC_BAD_EXE在這條線。 sp_error createErrorCode = sp_session_create(&config, &_session);

enter image description here

UPDATE

我發現exet其中做大量的搜索之後得到BAD_EXC

在這種方法

+(void)dispatchToLibSpotifyThread:(dispatch_block_t)block waitUntilDone:(BOOL)wait { 

    NSLock *waitingLock = nil; 
    if (wait) waitingLock = [NSLock new]; 

    // Make sure we only queue one thing at a time, and only 
    // when the runloop is ready for it. 
    [runloopReadyLock lockWhenCondition:1]; 

    CFRunLoopPerformBlock(libspotify_runloop, kCFRunLoopDefaultMode, ^() { 
     [waitingLock lock]; 
     if (block) { @autoreleasepool { block(); } } 
     [waitingLock unlock]; 
    }); 

    if (CFRunLoopIsWaiting(libspotify_runloop)) { 
     CFRunLoopSourceSignal(libspotify_runloop_source); 
     CFRunLoopWakeUp(libspotify_runloop); 
    } 

    [runloopReadyLock unlock]; // at hear when my debug poin reach after pass this i got bad_exc 
    if (wait) { 
     [waitingLock lock]; 
     [waitingLock unlock]; 
    } 
} 

回答

1

我得到了解決辦法,我檢查是否該會議已經存在,然後我把條件如: -

-(void)OpenSpotify 
{ 

    SPSession *session = [SPSession sharedSession]; 
    if (!session) { 
     NSError *error = nil; 
     [SPSession initializeSharedSessionWithApplicationKey:[NSData dataWithBytes:&g_appkey length:g_appkey_size] 
                userAgent:@"com.mycomp.spotify" 
               loadingPolicy:SPAsyncLoadingImmediate 
                 error:&error]; 
     if (error != nil) { 
      NSLog(@"CocoaLibSpotify init failed: %@", error); 
      abort(); 
     } 
     [[SPSession sharedSession] setDelegate:self]; 

    } 
    [self performSelector:@selector(showLogin) withObject:nil afterDelay:0.0]; 

} 
-(void)showLogin 
{ 

    SPLoginViewController *controller = [SPLoginViewController loginControllerForSession:[SPSession sharedSession]]; 
    controller.allowsCancel = YES; 
    [self presentViewController:controller animated:YES completion:nil]; 
} 

現在沒有崩潰和做工精細。