If anyone experienced the issue below, please let me know if you were able to find a fix. I've spent a couple of days trying to come up with a solution, but no luck so far. I'm using XCode 4.5 with iOS 6 SDK Golden Master.
Basically, my application reads and HTML file and hands its contents to a web view for rendering.
NSString *path = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"html"];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
NSURL *baseURL = [NSURL URLWithString:#"http://mysite.com"];
[webView loadHTMLString:html baseURL:baseURL];
The HTML contains a few <link> tags, for instance:
<link href="/webshare/accounts/maxk/styles/mobile_app_iphone_article.css?1312306173" media="screen" rel="stylesheet" type="text/css" />
The problem is, UIWebView seems to have troubles downloading the CSS file. The UIWebViewDelegate does receive webViewDidStartLoad right away, but it takes about 5 minutes before it receives webViewDidFinishLoad message. CSS is not picked up.
If I remove the link from HTML, everything works normally.
I had a similar issue in my web views once iOS 6 came out. Try setting the following UIWebView property to true (YES) { only available in iOS 6+ }:
suppressesIncrementalRendering
A Boolean value indicating whether the web view suppresses content rendering until it is
fully loaded into memory.
#property(nonatomic) BOOL suppressesIncrementalRendering
Basically in my circumstances the async content loading created a bit of an odd race condition that wasn't there before. Took me a while to find that one. I also agree with Brian though -- use some proxy software and watch your traffic to verify everything you need is coming in and when it comes in. That can be very useful.
Let me know if it helps?
Without having direct access to the project, it's really hard to say. Have you tried to loading the page in a local browser to confirm that the css is indeed being loaded? If it is loading, then I'd suggest running the app in the simulator while also running something like Charles proxy. Charles will record all of your outbound requests and display the results of them. That way, you can determine whether the issue is truly internal or external to the sdk.
If you do have an apple developer account, check out WWDC 2012 Session videos. You can find them here: https://developer.apple.com/videos/wwdc/2012/. There is one video titled, "Debugging UIWebViews and Websites on iOS". I haven't watched it yet, but it may contain some info that will help you resolve the issue.
Good luck!
So if the all css and other stuff is on remote server, why do you load html from the local file? Probably this is something security related (you are trying to load html from the local file while other stuff from remote), or just problem with handling of baseURL in UIWebView
Related
I have a custom url scheme working well, but there is one small behaviour I am hoping to change... Currently the inbound url is captured and processed in the following code (so, all good here):
- (void) handleURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
//I parse and deal with the url here//
}
Is it possible to avoid my app becoming the frontmost application? Whenever the url is received, my app is open already, as I initiated the communication from this app, and are merely listening for the reply. However, sometimes the call is made via an NSTimer so my app may or may not be the frontmost app. I don't want to disrupt the workflow if I am currently say browsing pages in Safari by having my app take the focus from Safari. I hope this makes sense.
Is this possible?
For anyone who's interested i instead set up a group container. I save my payload to the group defaults and then send an NSDistributedNotification from my helper app. The main app gets the notification, and reads the payload data from group defaults.
Such a workaround... but its necessary as both the main and helper apps are sandboxed.
I also discovered that KVO on group defaults doesn't work in the sandbox, and neither does sending a userDictionary in the NSDistributedNOtification.
:(
I have had to write sooo much extra code to make my app play nicely in the sandbox.
One of my app's features is to download a mp4 file and store it to the local phone album.
I have tried several approaches since and the result is always the same, it worked on the simulator but not on the actual iPhone. Xcode is version 5.0.1, iPhone 4.
Below is the code I applied on the last attempt before posted here using ASIHttpRequest library and the result is still the same, it worked on the simulator but not the phone itself.
download:
ASIHTTPRequest* request = [ASIHTTPRequest requestWithURL:url]; // url is the address to the mp4 file
NSString* filePath = [NSString stringWithFormat:#"%#%#", NSTemporaryDirectory(), filename]; //filename is the file I save to, e.g. xxx.mp4
[request setDownloadDestinationPath:filePath];
[request setDelegate:self];
[request setDidFinishSelector:#selector[ASIRequestDone:)];
[request setDidFailSelector:#select[ASIRequestFail:)];
when download is finished, save it to the photo album (in ASIRequestDone delegate)
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(filePath))
{
//comes to here when running in simulators
UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, #selector(video:didFinishSavingWithError:cotextInfo:),nil);
}
else
{
//always comes to here when running on the actual iPhone.
}
I have checked the pathFile it's this
/private/var/mobile/Applications/xxxxxxxxxx/tmp/xxxxx.mp4
which is alright to me. What I am not getting is it works fine when running on Simulator and hence I am stuck not sure what to do next. (I have also checked the permission accessing the the photo albums and yes the app has it).
I also tried to removed the compatible checking and went straight into the method UISaveVideoAtPathToSavedPhotosAlbum, it didn't throw any error on delegate didFinishSavingWithError. however, the video didn't show up on the photo album either, I am guessing it's correct as the phone seems to say that video is not compatible to be shown on the album. Again, my issue is that it does work on the simulator and how do I fix this on the actual iphone, e.g. why it thinks the video is not compatible? is something to do with the mp4 itself or is it something to do during the download step? What could I do next to resolve the issue? (ps. I also have control over the mp4 files, is there a list of mp4 compatibility on the iphone that you know? I am thinking perhaps it's genuine that the file is not compatible on the phone (but on the simulator!?))
Found the answer to my question and I hope it could help out someone who suffers from the same issue. Turns out video resolution is the factor between the simulator and the actual phone when it comes to store video to the gallery; to be specific:
Compatibility checking UIVideoAtPathIsCompatibleWithSavedPhotosAlbum would FAIL on the actual phone but would PASS on the simulator given a sample clip capturrd as 1080p. I came cross this link a week after my post with luck.
"What video formats are compatible with the assets library?"
And I did the experiment similar to that by capturing 720p video clips instead and all files were able to be saved to the gallery. Weird thing is that the actual iphone can play the HLS stream at 1080p; howeve it won't store clips unless they are 720p, not to me anyway. And the misleading bit is that the simulator can actually do 1080p.
How can I open an image obtained from the Assets Library in the default 'Photos' app on iPhone? Ideally this should work without temporally storing a second instance of the image in my app's document folder.
I tried the following but there is no URL hook for "assets-library://":
NSURL *url = [NSURL URLWithString:#"assets-library://asset/asset.JPG?id=523360F1-385B-4E2D-8DF0-DA893AC631CE&ext=JPG"];
[[UIApplication sharedApplication] openURL:url];
Perhaps the better way is to use UIDocumentInteractionController, but it seems it would require saving the image to my documents folder first, which takes a few seconds on my device.
Thank you for any help!
Klaus
I don't believe iOS supports a URL scheme for opening specific photos in the photos app. If you want such a scheme to exist, the best you can do is file a radar.
I am trying to do a really basic sharing on Facebook from my app, with ShareKit. Most things looks ok, but I don't understand why there's no icon to the left, just the small one in the footer. I can't find a way to put it there. How do I customize it? For me it looks like the left picture I attach, but I would like to have it like the right.
NSURL *url = [NSURL URLWithString:#"http://itunes.apple.com/us/app/...?mt=8"];
item = [SHKItem URL:url title:[NSString stringWithFormat:#"I'm playing someGame on my iPhone! My Highscore is %i, think you can beat it?", 456]];
[SHKFacebook shareItem:item];
You cannot out of the box. This dialog is provided by the Facebook SDK, which is just built into ShareKit's files - unchanged.
I am sure if you do a bit of digging around in ShareKit's folders you'll find the Facebook SDK, but I am not sure if you're allowed to edit its appearance (I know you aren't allowed to change the Share button for example)
With regards to the icon - this is loaded from the web and cannot be changed. The dialog comes from the Facebook website directly and somehow intercepting it and putting it on your own website would create an invalid request.
Edit: Based on your lovely edit (love the spray annotations :P), you can achieve this in the settings page for your app in Facebook. To do this, head over to Facebook's developer app (should be in the applications section of your Facebook account) and upload a large resolution icon for your app. Remember, it asks for a small 16x16 icon and the same one in different sizes, if it finds no icon with the sufficient size it'll display nothing.
I need a UIWebView to show a html page. if internet is not available it will show the last downloaded version. if has internet then it downloads the most current version and replaces and shows the version just downloaded. how can I do this? Thanks
You could implement you webViews delegate webViewDidFinishLoad: method to grab the request and load it again. Since it was just finished loading, we can assume that it is cached and load it with synchronous networking. Store the result. When network is unavailable load that result into the webView using loadData:MIMEType:textEncodingName:baseURL:. When network comes available agin just call loadRequest: to refresh.
Another option is to use stringByEvaluatingJavaScriptFromString: with a javascript around:
document.getElementsByTagName('html')[0].outerHTML;
and inserting the content with loadHTMLString:baseURL:
But these two only work for pure HTML without images, sounds, etc.
A third option would be to use the NSURLRequestReturnCacheDataDontLoad when network is not available. see NSURLRequest
You migth also have a look at the NSURLCache