UIWebView在应用商店版本中的行为与开发版本不同 [英] UIWebView acts differnetly in app store version than dev version

查看:114
本文介绍了UIWebView在应用商店版本中的行为与开发版本不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个在模拟器中完美运行的应用程序以及物理iPhone 4和iPhone 3GS的问题。该应用程序已获批准,现在已在App Store中,但从App Store下载的分发版本显示了开发/发布版本中未见的错误。

I've got a problem with an app that works perfectly in the simulator as well as a physical iPhone 4 and an iPhone 3GS. The app was approved and is now in the App Store, but the distribution build downloaded from the App Store exhibits a bug not seen in the dev/release build.

这是一个免费的应用程序,但由本地广告支持。当应用程序启动(或从后台返回)时,AppDelegate会尝试从我们的广告服务器下载一些HTML,如果成功,则会提供一个带有UIWebView的模态视图控制器,并传递包含HTML的NSData变量。在开发/发布版本中,这可以完美地工作;应用程序启动,几秒钟后,视图会向上滑动并显示广告,可以通过按钮将其解除。

This is a free app, but is supported by local advertising. When the app launches (or returns from background), the AppDelegate attempts to download some HTML from our ad server, and if successful, presents a modal view controller with a UIWebView and passes an NSData variable containing the HTML. In development/release builds, this works PERFECTLY; the app launches, and after a few seconds, a view slides up and shows the ad, which can be dismissed with a button.

然而,App Store中的分发版本是不同。当模态视图控制器向上滑动时,UIWebView永远不会加载。请记住,如果能够下载广告数据,我只会提供视图控制器 - 否则,视图永远不会显示。

However distribution build from the App Store is different. When the modal view controller slides up, the UIWebView never loads. Remember, I present the view controller ONLY if able to download the ad data -- otherwise, the view is never presented.

谢天谢地我在广告视图控制器中实现了一个计时器如果webViewDidFinishLoad永远不会触发(其中计时器无效),这将导致模态视图自行解散,因此至少应用程序用户不会太烦恼。但是让一个空的视图控制器向上滑动然后滑动显然没有理由仍然是丑陋的。

Thankfully I implemented a timer in the ad view controller which will cause the modal view to dismiss itself if the webViewDidFinishLoad never fires (in which the timer is invalidated), so at least app users aren't too annoyed. But it's still ugly to have an empty view controller slide up and then slide away for apparently no reason.

以下是AppDelegate中的相关方法:

Here's the relevant methods in the AppDelegate:

- (void)launchAd
{
    [NetworkActivity showFor:@"ad"];

    if (!alreadyActive && [ServerCheck serverReachable:@"openx.freewave-wifi.com" hideAlert:YES])
    {  
        alreadyActive = YES;

        [self performSelectorInBackground:@selector(downloadAdData) withObject:nil];
    }

    [NetworkActivity hideFor:@"ad"];
}

- (void)downloadAdData
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSString *baseURL = @"http://appdata.freewave-wifi.com/ad/";

    NSString *file = (IS_IPAD) ? @"ipad.php" : @"iphone.php";

    NSURL *adURL = [NSURL URLWithString:[baseURL stringByAppendingString:file]];

    adData = [[NSData alloc] initWithContentsOfURL:adURL];

    [self performSelectorOnMainThread:@selector(presentAdModal) withObject:nil waitUntilDone:NO];

    [pool release];
}

- (void)presentAdModal
{
    if (adData)
    {
        AdViewController *adView = [[AdViewController alloc] initWithNibName:nil bundle:nil];
        [adView setAdData:adData];

        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:adView];


        [navController setModalPresentationStyle:UIModalPresentationFormSheet];
        [navController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

        [tabBarController presentModalViewController:navController animated:YES];

        [navController release], navController = nil;
        [adView release], adView = nil;
    }
    else
        LogError(@"Not presenting ad; unable to create data object.");
}

顺便说一句,adData在标题中用定义NSData * adData;

By the way, adData is defined in header with NSData *adData;

AdViewController只包含一个UIWebView,它载有

The AdViewController simply contains a UIWebView, which is loaded with

[webView loadData:adData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];

同样,这一切都完美无缺,每次都可以在模拟器和物理设备中使用dev / release构建 - 只是没有从应用商店的分布构建。我甚至已经将NSData转换为NSString并使用NSLog()进行了禁止,以证明在下载AdView之前已经下载了HTML。

Again, this all works PERFECTLY, EVERY TIME with dev/release builds in simulator and physical devices -- just not on distribution build from app store. I have even converted the NSData to an NSString and barfed it out with NSLog() just to prove that the HTML was downloaded before presenting the AdView modally.

[叹气.. 。]

编辑1 :如果我的原始帖子不清楚, webViewDidFinishLoad 永远不会在分发版本中调用(但它在dev / release版本中调用)。

EDIT 1: In case my original post was not clear, the webViewDidFinishLoad never gets called in distribution build (but it does in dev/release build).

编辑2 :此外,就在我打电话之前

EDIT 2: Also, just before I call

[webView loadData:adData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:nil];

在AdViewController中,我添加了一个临时的 NSLog()并将adData转换为NSString并将其记录到控制台,HTML就在那里。那么,UIWebView只是拒绝加载NSData?

in the AdViewController, I added a temporary NSLog() and converted adData to NSString and logged it to the console, and the HTML was there. So, the UIWebView just refuses to load the NSData?

推荐答案

HOLY COW。我弄清楚了。

HOLY COW. I figure it out.

好吧,在我说出我发现的内容之前,我确实想要纠正我自己的原始措辞:模态广告从未在模拟器中工作,但是总是在设备上。我知道模拟器可以有它的怪癖,所以我从来没有想过它,特别是因为它总是在设备上工作。我知道这是一个重要的细节,这个讨论缺少了,但是自从我参与这个项目以来已经有几个星期了,直到今天我都忘了这一切。

Okay, before I say what I found, I did want to correct my own original wording: the modal ad has never worked in the simulator, but always on devices. I know the simulator can have its quirks, so I never thought anything of it, especially since it always worked on the devices. I know this is an important detail that was missing for this discussion, but it's been a couple of weeks since I worked on this project, and I'd forgotten all about it until today.

现在......在修补东西时,我注意到AdView.xib不在我的项目文件列表中。我扩展了一些文件夹,认为它可能被意外拖入其中一个,但它根本没有列出。这真让我感到困惑,但是 - Xcode从不抱怨资源缺失(没有警告或错误;总是完美的编译)。

Now then... While tinkering with things, I noticed the AdView.xib was not in my project file list. I expanded a few folders thinking maybe it was accidentally dragged into one of them, but it was not listed at all. This really has me puzzled, though -- Xcode NEVER complained about a missing resource (no warnings or errors; always a perfect compile).

所以,我导航到物理位置并将AdView.xib添加到项目中。现在,模态广告显示在模拟器中,这是第一个。我认为,由于现在应用程序在模拟器中正常工作,它应该在分发版本中正常工作(奇怪的相关性,但是我得到的只是我的更新到达App Store)。

So, I navigated to the physical location and added the AdView.xib into the project. Now, the modal ad is displayed in the simulator, which is a first. I figure that since now the app works correctly in the simulator, it should work fine in the distribution build (odd correlation to make, but it's all I got until my update hits the App Store).

显然,我将提交更新,所以在更新到App Store之前我不会接受我自己的答案(假设我已经修好了)。

Obviously, I'll be submitting an update, so I won't accept my own answer until after the update hits the App Store (assuming I have actually fixed it).

这篇关于UIWebView在应用商店版本中的行为与开发版本不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆