Facebook 检查设备上是否登录服务时无法再现应用程序崩溃

Facebook 检查设备上是否登录服务时无法再现应用程序崩溃,facebook,twitter,crash,exc-bad-access,acaccount,Facebook,Twitter,Crash,Exc Bad Access,Acaccount,根据崩溃日志,我有一个应用程序在启动时崩溃,同时检查用户是否在设备上登录Facebook。问题是我无法重现这种崩溃,它发生在不同的设备上。到目前为止,我只在iOS 6之前的操作系统中见过这种崩溃。我的应用最早支持的iOS是4.3 下面是代码,如果有人能提供一个线索,说明为什么这个方法有时会失败(大多数情况下不会!) 我得到的错误是EXC_BAD_ACCESS(SIGSEGV);内核地址在0x00000000处无效 + (BOOL)loggedIntoServiceOnDevice:(in

根据崩溃日志,我有一个应用程序在启动时崩溃,同时检查用户是否在设备上登录Facebook。问题是我无法重现这种崩溃,它发生在不同的设备上。到目前为止,我只在iOS 6之前的操作系统中见过这种崩溃。我的应用最早支持的iOS是4.3

下面是代码,如果有人能提供一个线索,说明为什么这个方法有时会失败(大多数情况下不会!)

我得到的错误是EXC_BAD_ACCESS(SIGSEGV);内核地址在0x00000000处无效

    + (BOOL)loggedIntoServiceOnDevice:(int)socialService {

        __ENTERING_METHOD__
        BOOL loggedIntoServiceOnDevice = NO;
        ACAccountStore *accountStoreHere = [[NSClassFromString(@"ACAccountStore") alloc] init];
        ACAccountType *accountType;
        ACAccountType *accountType2;

        if (accountStoreHere) {
            if (socialService == FACEBOOK_SERVICE) {

                ACAccountType *accountType = [accountStoreHere accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"];
                Class slComposeController = NSClassFromString(@"SLComposeViewController");
                if (accountType && slComposeController != nil)
                {
                    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

                         loggedIntoServiceOnDevice = YES;
                    }
                }
            }
            else if (socialService == TWITTER_SERVICE) {
                ACAccountType *accountType = [accountStoreHere accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
                if (accountType)
                {
                    Class slComposeController = NSClassFromString(@"SLComposeViewController");
                    if ([TWTweetComposeViewController canSendTweet] || slComposeController != nil) {
                        if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {

                            loggedIntoServiceOnDevice = YES;
                        }
                    }
                }
            }
        }
        [accountStoreHere release];
        return loggedIntoServiceOnDevice;
    }

由于
[twtweetcomoseviewcontroller canSendTweet]
正在返回
YES
,因此在iOS 5中也会执行以下行,因为第一部分已返回
YES
,因此不会评估
检查的第二部分:

[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]
您可能希望将这些if语句更改为以下内容:

if ([TWTweetComposeViewController canSendTweet] ||
    (
     slComposeController != nil &&
     [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]
    )
   ) {
这确保只有在类实际存在时才使用
SLComposeViewController