2012-03-27 73 views
0

我猜測,因爲這代碼辜負我的iOS4的設備上這必須是新的功能,做工精細的iOS5上。我需要這兩個工作。我還沒有搬到iOS5,但我仍然需要支持iOS4,所以我不知道如何解決這個問題?獲得EXC_BAD_ACCESS,而不是在iOS 5中

static dispatch_once_t oncePredicate; 
dispatch_once(&oncePredicate, ^{ //EXC_BAD_ACCESS 
    _sharedStoreManager = [[super allocWithZone:nil] init];    
}); 

這是一個從https://github.com/MugunthKumar/MKStoreKit/blob/master/MKStoreManager.m

+0

'dispatch_once'可在iOS 4.0及更高版本。你能提供更多關於墜機的信息嗎? – 2012-03-27 21:16:29

+1

你能告訴我們你的回溯? – 2012-03-27 21:21:08

回答

4

dispatch_once()是不是新的iOS 5.0,它已經出現自4.0。我用它所有的時間在目標4.0的應用程序,比如從我的框架之一這個單:

+ (GPUImageOpenGLESContext *)sharedImageProcessingOpenGLESContext; 
{ 
    static dispatch_once_t pred; 
    static GPUImageOpenGLESContext *sharedImageProcessingOpenGLESContext = nil; 

    dispatch_once(&pred, ^{ 
     sharedImageProcessingOpenGLESContext = [[GPUImageOpenGLESContext alloc] init]; 
    }); 
    return sharedImageProcessingOpenGLESContext; 
} 

Apple's documentation

可用性

可提供的iOS 4.0然後。

我猜你的問題存在於_sharedStoreManager的-init內。例如,你在那裏使用-allocWithZone:有什麼原因嗎?

1

dispatch_onceis available,並沒有什麼錯,你已經發布的片段。

我看到兩個問題的代碼的其餘部分,不過,從兩行所產生194.首先,經理正在發送init兩次:一次是在dispatch_once塊內,並在此之後,在該行:

if(!_sharedStoreManager) { 
    static dispatch_once_t oncePredicate; 
    dispatch_once(&oncePredicate, ^{ 
     _sharedStoreManager = [[super allocWithZone:nil] init];    
    }); 

    #if TARGET_IPHONE_SIMULATOR 
    NSLog(@"You are running in Simulator MKStoreKit runs only on devices"); 
    #else 
/*194*/_sharedStoreManager = [[self alloc] init]; 

這是一個不好的事情。

導致該,更重要的是,雖然是這看起來像一個無限循環。線194有來電+[MKStoreManager alloc],這將在+[MKStoreManager allocWithZone:]結束,再次呼籲+sharedManager

+ (id)allocWithZone:(NSZone *)zone 
{ 
    return [self sharedManager]; 
} 

我不會認爲這樣的循環會導致EXC_BAD_ACCESS,但我建議刪除第194行;這是不正確的。

(我也建議固定if塊的縮進。)

2

這是通過我的代碼中的錯誤造成的,我已經推了修復它。更新你的子模塊。感謝Brad Larson通知我。