我现在正在开发一个 Iphone 应用程序,该应用程序需要用户登录 Facebook 并将他们的数据传递给 webService 并登录到我的游戏。基本上我的游戏是由 HTML 运行的,它将由 UIWebView 在我的应用程序中显示。
这是我加载 webView 的代码:
-(void)callWebView {
self.webView.delegate = self;
NSURL *url = [NSURL URLWithString:@"http://www.my_game_url"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:requestURL];
}
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
if ( [ urlString isEqualToString: @"http://my_game_logout_url" ] ) {
[myWebView stopLoading];
[self.webView removeFromSuperview];
MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
return NO;
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[self.webView stopLoading];
MyAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
webView.delegate = nil;
[webView stopLoading];
}
- (void)dealloc {
[webView setDelegate:nil];
}
用 UIWebView 运行我的游戏很好。问题是我稍后会收到内存警告,我的应用程序会崩溃。我必须启用自动引用计数 (ARC) 以自动释放一些不需要的源,但我仍然会在我的应用程序中收到内存警告。我有什么错误吗?谢谢。