gpt4 book ai didi

ios - FBSession : should only be used from a single thread

转载 作者:可可西里 更新时间:2023-11-01 04:53:20 25 4
gpt4 key购买 nike

我正在使用 facebook sdk 3.5 开发一个用于在 ios 中发布 FB 墙的应用程序。我正在使用两个 View 。第一个是启动画面,第二个是 facebook 登录 View 。当我激活这两个 View 时,我得到一个线程并显示错误,

 2013-05-17 17:07:59.115 [415:12503] * Assertion failure in -[FBSession checkThreadAffinity], /Users/chrisp/tmp/sdk/ios-sdk/src/FBSession.m:1571

2013-05-17 17:07:59.127 [415:12503] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“FBSession:只能从单个线程使用”* 首先抛出调用栈:(0x2387052 0x1fa3d0a 0x232fa78 0x1a9c2db 0x21fa2 0x1e626 0x1ecd9 0x22b67 0x1eba3 0x3c265 0x2388ec9 0x11165c2 0x111655a 0x11bbb76 0x11bc03f 0x11bb2fe 0x113ba30 0x113bc56 0x1122384 0x1115aa9 0x293ffa9 0x235b1c5 0x22c0022 0x22be90a 0x22bddb4 0x22bdccb 0x293e879 0x293e93e 0x1113a9b 0x2be2 0x2b15)终止调用抛出异常(lldb)

这是我的 Appdelegate.m 代码,

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
// Override point for customization after application launch.

self.viewController = [[[SplashViewController alloc] initWithNibName:@"SplashViewController" bundle:nil]autorelease] ;

// self.loginViewController = [[secondview alloc] initWithNibName:@"secondview"
// bundle:nil];
// self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.loginViewController];

// self.navigationController.delegate = self;

// self.window.rootViewController = self.navigationController;


self.window.rootViewController = self.viewController;

[self.window makeKeyAndVisible];
return YES;

//
//
UIBackgroundTaskIdentifier backgroundTask = [application beginBackgroundTaskWithExpirationHandler:^{NSLog(@"BackgroundTask Expiration Handler is called");
[application endBackgroundTask:backgroundTask];
}];

这是 facebook_view.m 代码

     - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidUnload {
[self setFBLoginView:nil];
[super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - FBLoginView delegate

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
// Upon login, transition to the main UI by pushing it onto the navigation stack.
TNLRadioAppDelegate *appDelegate = (TNLRadioAppDelegate *)[UIApplication sharedApplication].delegate;
[self.navigationController pushViewController:((UIViewController *)appDelegate.viewController) animated:YES];
}
- (void)loginView:(FBLoginView *)loginView
handleError:(NSError *)error{
NSString *alertMessage = nil, *alertTitle;

// Facebook SDK * error handling *
// Error handling is an important part of providing a good user experience.
// Since this sample uses the FBLoginView, this delegate will respond to
// login failures, or other failures that have closed the session (such
// as a token becoming invalid). Please see the [- postOpenGraphAction:]
// and [- requestPermissionAndPost] on `SCViewController` for further
// error handling on other operations.

if (error.fberrorShouldNotifyUser) {
// If the SDK has a message for the user, surface it. This conveniently
// handles cases like password change or iOS6 app slider state.
alertTitle = @"Something Went Wrong";
alertMessage = error.fberrorUserMessage;
} else if (error.fberrorCategory == FBErrorCategoryAuthenticationReopenSession) {
// It is important to handle session closures as mentioned. You can inspect
// the error for more context but this sample generically notifies the user.
alertTitle = @"Session Error";
alertMessage = @"Your current session is no longer valid. Please log in again.";
} else if (error.fberrorCategory ==
FBErrorCategoryUserCancelled) {
// The user has cancelled a login. You can inspect the error
// for more context. For this sample, we will simply ignore it.
NSLog(@"user cancelled login");
} else {
// For simplicity, this sample treats other errors blindly, but you should
// refer to https://developers.facebook.com/docs/technical-guides/iossdk/errors/ for more information.
alertTitle = @"Unknown Error";
alertMessage = @"Error. Please try again later.";
NSLog(@"Unexpected error:%@", error);
}

if (alertMessage) {
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}
}

- (void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView {
// Facebook SDK * login flow *
// It is important to always handle session closure because it can happen
// externally; for example, if the current session's access token becomes
// invalid. For this sample, we simply pop back to the landing page.
TNLRadioAppDelegate *appDelegate = (TNLRadioAppDelegate *)[UIApplication sharedApplication].delegate;
if (appDelegate.isNavigating) {
// The delay is for the edge case where a session is immediately closed after
// logging in and our navigation controller is still animating a push.
[self performSelector:@selector(logOut) withObject:nil afterDelay:.5];
} else {
[self logOut];
}
}

- (void)logOut {
[self.navigationController popToRootViewControllerAnimated:YES];
}

Cqan 有谁帮忙吗???

最佳答案

听起来您正在从多个线程访问您的 FBSession 实例。检查您是否没有从后台线程调用 [FBSession activeSession] 或任何类似的东西(或者您总是从同一个后台线程调用它)。

关于ios - FBSession : should only be used from a single thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16608259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com