我正在使用Google plus最新框架(google-plus-ios-sdk-1.7.0)。在Google+共享上崩溃。执行方法shareGooglePlusWithMessage之后,应用会在控制台上崩溃并显示以下消息。请帮我
- (void) loginGooglePlusWithClientId:(NSString*) clientId
{
clientId = kGooglePlus_CLientId;
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.clientID = clientId;
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.shouldFetchGoogleUserID = YES;
[GPPSignIn sharedInstance].s`enter code here`copes = [NSArray arrayWithObjects:kGTLAuthScopePlusLogin,kGTLAuthScopePlusMe,nil];
signIn.delegate = self;
[signIn authenticate];
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth error: (NSError *) error
{
NSLog(@"G+ User Id : %@", [NSString stringWithFormat:@"%@", [GPPSignIn sharedInstance].userID]);
NSLog(@"Received error %@ and auth object %@",error, auth);
if(auth && !error)
{
[self shareGooglePlusWithMessage:@"" andLink:@""];
}
}
- (void) shareGooglePlusWithMessage:(NSString*) msg andLink:(NSString*) urlStr
{
urlStr = @"https://www.techaheadcorp.com";
msg = @"Test Message";
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
if(urlStr)
[shareBuilder setURLToShare:[NSURL URLWithString:urlStr]];
if(msg)
[shareBuilder setPrefillText:msg];
if(urlStr || msg)
[shareBuilder open];
}
- (void)finishedSharingWithError:(NSError *)error
{
if(error == nil)
NSLog(@"Success G+ Sharing");
//else
//NSLog(@"Failed G+ Sharing with error : %@", [error description]);
}
- (void)finishedSharing:(BOOL)shared
{
}
***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'***-[__ NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从对象中插入零对象[1]'
***首先抛出调用堆栈:
(
0 CoreFoundation 0x041b81e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03ab68e5 objc_exception_throw + 44
2 CoreFoundation 0x0417e376-[__ NSPlaceholderDictionary initWithObjects:forKeys:count:] + 390
3 CoreFoundation 0x041abc29 + [NSDictionary dictionaryWithObjects:forKeys:count:] + 73
4 PineWallet 0x003d7384-[GPPOzLogger flushEventsAndBuildQuery] + 667
5 PineWallet 0x003a394d-[GPPServiceBase executeQuery:usingService:batchLogsFrom:completionHandler:] + 868
6 PineWallet 0x003da0bb-[GPPService executeQuery:usingService:batchLogsFrom:completionHandler:] + 657
7 PineWallet 0x003da4a0 __72- [GPPService executeQuery:usingService:batchLogsFrom:completionHandler:] _ block_invoke + 157
8 PineWallet 0x003da76f __72- [GPPService executeQuery:usingService:batchLogsFrom:completionHandler:] _ block_invoke109 + 490
9 PineWallet 0x003a4424 __76- [GPPServiceBase executeQuery:usingService:batchLogsFrom:completionHandler:] _ block_invoke + 1984
10 PineWallet 0x00366e45-[GTLService handleParsedObjectForFetcher:] + 1694
11 libobjc.A.dylib 0x03ac882b-[NSObject performSelector:withObject:] + 70
12 Foundation 0x0370ae48 __NSThreadPerformPerform + 285
13 CoreFoundation 0x0414177f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
14 CoreFoundation 0x0414110b __CFRunLoopDoSources0 + 235
15 CoreFoundation 0x0415e1ae __CFRunLoopRun + 910
16 CoreFoundation 0x0415d9d3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x0415d7eb CFRunLoopRunInMode + 123
18 GraphicsServices 0x0503c5ee GSEventRunModal + 192
19 GraphicsServices 0x0503c42b GSEventRun + 104
20个UIKit 0x02776f9b UIApplicationMain + 1225
21 PineWallet 0x0000294d主+ 141
22 libdyld.dylib 0x04a69701开始+ 1
23 ??? 0x00000001 0x0 +1
)
libc ++ abi.dylib:以NSException类型的未捕获异常终止
最佳答案
首先,我将逐个断点逐行查看您要在哪里插入nil对象。
作为参考,我将在这里添加我的Google+共享代码:
-(void)shareOnGooglePlus
{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kClientId;
signIn.scopes = @[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn authenticate];
}
- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation
{
return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error
{
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
NSString *shortDescription = [self.objectToShare valueForKey:@"descriptionShort"];
NSString *shareText = @"";
if (shortDescription.length > 0)
{
shareText = [NSString stringWithFormat:LOCALIZEDSTRING(@"share_text_default"), [self.objectToShare valueForKey:@"name"], [self.objectToShare valueForKey:@"descriptionShort"]];
}
else
{
shareText = [NSString stringWithFormat:LOCALIZEDSTRING(@"share_text_no_short"), [self.objectToShare valueForKey:@"name"]];
}
NSURL *shareUrl = [NSURL URLWithString:ITUNES_URL];
[shareBuilder setURLToShare:shareUrl];
[shareBuilder setPrefillText:shareText];
[shareBuilder open];
}
另外,请确保已设置有效的URL类型(项目->目标->信息-> URL类型)