我已经在 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
按主页按钮退出 Safari 的 Facebook SSO 页面
applicationWillEnterForeground - upon pressing app icon
委托的 dealloc 在 applicationWillEnterForeground 结束后不久被调用
(在一些汇编代码之后调用的第一个函数:
mov 0x56314c(%ebx),%esi
xor %eax,%eax
test %al,%al
mov 0x8(%ebp),%ecx
=> 解除分配
我真的不知道这里发生了什么,我已经尝试在谷歌上搜索很长一段时间的答案,有人可以帮助解释为什么会这样吗?
我正在使用 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。按主页按钮退出 Safari 并单击应用程序图标将首先调用:
applicationWillEnterForeground
然后它调用了RegistrationViewController的dealloc函数,这是我不明白的部分,因为RegistrationViewController应该已经被Navigation Controller保留了不是吗?为什么要执行dealloc?
另外,在我的 RegistrationViewController dealloc 例程中,由于我已经使用 sharedApplication 在我的 RegistrationViewController 中声明了一个 _delegate 指针,我认为只有在不再需要 RegistrationViewController 时才解除它是合乎逻辑的,但是为什么 [_delegate release] 会导致永久消亡我的代表?委托不应该一直由其他人保留吗?