Facebook SSO 的 applicationWillEnterForeground 之后出现奇怪的委托 dealloc 调用

发布于 2024-11-07 22:34:53 字数 2070 浏览 3 评论 0原文

我在 Google 上使用以下关键字搜索了很长一段时间,但一无所获:

+applicationDidEnterBackground +applicationWillEnterForeground +Facebook +dealloc +SSO

这是我的问题陈述:

如果我按主页按钮暂停应用程序并单击应用程序图标来恢复它,无论我尝试了多少次,以下函数都将以正确的顺序调用,并且不会调用 dealloc 函数:

applicationDidEnterBackground - upon pressing home button
applicationWillEnterForeground - upon pressing app icon

然后,如果在应用程序中我开始调用 Facebook 的 SSO:

[facebook authorize:_permissions delegate:self];

奇怪发生的事情:

applicationDidEnterBackground - upon Facebook SSO

按 home 按钮退出 Safari 的 Facebook SSO 页面

applicationWillEnterForeground - upon pressing app icon

委托的 dealloc 在 applicationWillEnterForeground 结束后不久被调用

(在一些汇编代码之后调用的第一个函数:

mov    0x56314c(%ebx),%esi
xor    %eax,%eax
test   %al,%al
mov    0x8(%ebp),%ecx

=> dealloc

我真的不知道这里发生了什么,我已经尝试过在 Google 上搜索答案已经有一段时间了,有人可以帮助解释为什么会发生这种情况吗?

我使用的是 Facebook 版本“kSDKVersion = @”2“;”

信息:

附加 研究一下这个问题,我认为问题更深层地在于当应用程序再次进入前台时我的视图控制器如何与导航控制器交互:

我的 Facebook SSO 在 RegistrationViewController 的 XIB 中调用,其中用户单击按钮进入 SSO 会话,以显示RegistrationViewController,我使用了以下代码:

[_delegate.navigationController popViewControllerAnimated:NO];
_delegate.regViewController = [[RegistrationViewController alloc] initWithNibName:nil bundle:nil];
[_delegate.navigationController pushViewController:_delegate.regViewController animated:NO];
[_delegate.regViewController release];

用户单击 RegistrationViewController 内的按钮后,Safari 将打开。 按home按钮退出Safari并单击应用程序图标将首先调用:

applicationWillEnterForeground

然后它调用RegistrationViewController的dealloc函数,这是我不明白的部分,因为RegistrationViewController应该被Navigation Controller保留,不是吗?为什么要执行dealloc?

另外,在我的 RegistrationViewController dealloc 例程中,由于我使用共享应用程序在 RegistrationViewController 中声明了一个 _delegate 指针,我认为当不再需要 RegistrationViewController 时释放它才是合乎逻辑的,但为什么 [_delegate release] 会导致永久消亡我的代表?委托不应该一直由其他人保留吗?

I have searched quite a while for this answer with the following keywords on Google but I got nothing:

+applicationDidEnterBackground +applicationWillEnterForeground +Facebook +dealloc +SSO

Here is my problem statement:

If I press home button to suspend the application and click on the app icon to resume it, no matter how many times I tried, the following function will be called in the correct order, with no dealloc function being called:

applicationDidEnterBackground - upon pressing home button
applicationWillEnterForeground - upon pressing app icon

Then, if within an App I start a call to Facebook's SSO:

[facebook authorize:_permissions delegate:self];

Strange things happen:

applicationDidEnterBackground - upon Facebook SSO

Press home button to exit Safari's Facebook SSO page

applicationWillEnterForeground - upon pressing app icon

delegate's dealloc is called soon after applicationWillEnterForeground ends

(very first function called after some assembly codes:

mov    0x56314c(%ebx),%esi
xor    %eax,%eax
test   %al,%al
mov    0x8(%ebp),%ecx

=> dealloc

I don't really know what is going on here, and I have tried to search for the answers on Google for quite a while now, can someone help to explain why this is happening?

I am using Facebook version "kSDKVersion = @"2";".

Additional Information:

After taking a look into the problem, I think the problem lies deeper within how my view controller interacts with navigation controller when the app enters foreground again:

My Facebook SSO is invoked within RegistrationViewController's XIB where user clicks a button to enter SSO session, to display the RegistrationViewController, I used the following codes:

[_delegate.navigationController popViewControllerAnimated:NO];
_delegate.regViewController = [[RegistrationViewController alloc] initWithNibName:nil bundle:nil];
[_delegate.navigationController pushViewController:_delegate.regViewController animated:NO];
[_delegate.regViewController release];

After user clicks the button inside RegistrationViewController, Safari is opened.
Pressing home button to exit Safari and clicking the app icon will first call:

applicationWillEnterForeground

Then it calls the dealloc function of RegistrationViewController, which is the part I don't understand, since RegistrationViewController should have been retained by Navigation Controller isn't it? Why is it executing the dealloc?

Also, within my RegistrationViewController dealloc routine, since I have declared a _delegate pointer within my RegistrationViewController using sharedApplication, I think it is only logical to dealloc it when RegistrationViewController no longer is needed, but why would [_delegate release] lead to a permanent demise of my delegate? Shouldn't delegate be retained by someone else all the time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很快妥协 2024-11-14 22:34:53

我的问题的解决方案是我释放了我不应该释放的内容!

以下语句:

_delegate = (PHPConnectDemoAppDelegate *)[[UIApplication sharedApplication] delegate];

不会将应用程序委托的保留计数增加 1。

因此,没有必要在同一视图控制器的 dealloc 函数中执行:

[_delegate release];

否则应用程序委托的保留计数将下降到 0,从而导致永久您的应用程序委托的消亡。

不知何故,我认为我粘贴的汇编代码正在对保留计数进行评估,以决定是否释放应用程序委托,如果我错了,请纠正我。

The solution to my problem is that the fact I am releasing what I shouldn't be releasing!

The following statement:

_delegate = (PHPConnectDemoAppDelegate *)[[UIApplication sharedApplication] delegate];

will not increment the retain count to the app delegate by 1.

Therefore it is not necessary within the same View Controller's dealloc function to perform:

[_delegate release];

or else the retain count to your app delegate drops down to 0 hence leading to a permanent demise of your app delegate.

Somehow I think the assembly code I pasted is performing assessment on the retain count to decide whether to dealloc the app delegate or not, correct me if I am wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文