Google Plus共享崩溃

时间:2014-08-20 09:52:04

标签: ios objective-c ios7

我正在使用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
{

}
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(
    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 main + 141
    22  libdyld.dylib                       0x04a69701 start + 1
    23  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

1 个答案:

答案 0 :(得分:0)

对于初学者,我会逐行断点,看看你在哪里插入一个零对象。

作为参考,我将把我的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];
}

此外,请务必设置有效的网址类型(项目 - &gt;目标 - &gt;信息 - &gt;网址类型)

URLTYPE