You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS集成Facebook登录点击Continue后崩溃,报NSInvalidArgumentException异常求助

Fixing Facebook Login Crash on "Continue" Button Tap

Hey Daniel, let's break down this crash and get your Facebook login working smoothly again.

Root Cause Analysis

From your crash log, the key error line tells us everything we need to know:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:' -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[3]'

This means in your -[ViewController Callfb_LoginService:] method, you're trying to create an NSDictionary where the 4th element (index 3) in your objects array is nil. NSDictionaries don't allow nil values for keys or values, so this triggers an immediate crash.

Since the crash happens right after getting Facebook user details (seen in __33-[ViewController GetFBUserDetail]_block_invoke), the nil value is almost certainly coming from a field you're trying to pull from the Facebook Graph API response—something like email, birthday, or another permission-based field that the user didn't grant access to, or Facebook didn't return.


Step-by-Step Fixes

1. Locate the Dictionary Creation Code

First, find the section in Callfb_LoginService: where you're creating a dictionary with dictionaryWithObjects:forKeys:count: or a similar method. It'll look something like this:

NSArray *keys = @[@"user_id", @"name", @"profile_pic", @"email"];
NSArray *objects = @[fbUserId, fbUserName, fbProfilePic, fbEmail];
NSDictionary *loginParams = [NSDictionary dictionaryWithObjects:objects forKeys:keys count:4];

In this example, fbEmail (the 4th element, index 3) is the nil value causing the crash.

2. Handle Potential Nil Values

You have two solid options to fix this:

Option A: Use Default Values for Nil Fields

Replace any potentially nil values with a safe fallback (like an empty string):

NSString *fbEmail = [fbUserDetails objectForKey:@"email"] ?: @""; // Use empty string if nil
NSString *fbBirthday = [fbUserDetails objectForKey:@"birthday"] ?: @"N/A";
Option B: Filter Out Nil Key-Value Pairs

Use a mutable dictionary to only add non-nil entries:

NSMutableDictionary *loginParams = [NSMutableDictionary dictionary];

if (fbUserId) [loginParams setObject:fbUserId forKey:@"user_id"];
if (fbUserName) [loginParams setObject:fbUserName forKey:@"name"];
if (fbProfilePic) [loginParams setObject:fbProfilePic forKey:@"profile_pic"];
if (fbEmail) [loginParams setObject:fbEmail forKey:@"email"];

3. Add Debug Logs to Confirm the Issue

To double-check which field is nil, add a log right before creating the dictionary:

NSLog(@"FB User Data - ID: %@, Name: %@, Pic: %@, Email: %@", fbUserId, fbUserName, fbProfilePic, fbEmail);

This will print the values to your console, making it crystal clear which one is coming up nil.


内容的提问来源于stack exchange,提问作者DanielB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:43:38