I have an app that, according to crash logs, is crashing on startup while checking if the user is logged into Facebook on the device. The problem is that I cannot reproduce this crash, and it happens on different devices. So far, I have only seen this crash in pre-iOS 6 operating systems. The earliest iOS supported by my app is 4.3.
Here is the code, if anyone can provide a clue as to why this method sometimes fails (and most times does not!)
The error I get is EXC_BAD_ACCESS (SIGSEGV);KERN_INVALID_ADDRESS at 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;
}
The following line is also executed in iOS 5 since [TWTweetComposeViewController canSendTweet]
is returning YES
so the second part of the OR
check is not evaluated, since the first one already returned YES
:
[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]
You might want to change those if statements to something like:
if ([TWTweetComposeViewController canSendTweet] ||
(
slComposeController != nil &&
[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]
)
) {
This makes sure, that SLComposeViewController
is only used, if the class actually exists.