Open image from ALAsset representation in default Photos app - assets

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.

Related

UIVideoAtPathIsCompatibleWithSavedPhotosAlbum returns false when deploying on the iPhone

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.

iOS 6 - UIWebView loadHTMLString not working properly

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

Open Mobile Safari without using openURL:url

I want to open the Mobile Safari app "WITHOUT" changing its currently displayed page.
I can easily switch to Safari using ..
NSString *ourPath = #"http://www.google.co.uk";
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
But what I want to do is just switch to safari and not navigate away from the page it is currently on. Like when I switch using the task switcher, it just pops Safari and leaves it on the page it was.
I've tried sending it a url of #"http:" but this doesn't work it changes pages to to "http:localhost/"
Is there a way to just Open it?
Plasma
I solved this using the answers on this page ..
iOS How can I use UIApplication launchApplicationWithIdentifier which is in private APIs?
Though I didn't have to move my .app file in to /Applications
It was enough to add the entitlements, then simply call it using ...
[[UIApplication sharedApplication] launchApplicationWithIdentifier:#"com.apple.mobilesafari" suspended:NO];
Plasma
Could you open to a page that executes JavaScript history.back() when loaded?

How to programmatically add calendar subscriptions on iOS?

Via the settings panel of your iPhone, you can add a subscription to a remote .ics calendar format. I have a Dutch iPhone app that does this from within the app (see the screenshot below, "abonneren op de agenda" means "subscribe to the calendar"), but there must be others too.
I want to mimic this behavior for a project of mine, but I can't find the API to do this with. It looks like it's not a part of EventKit, but because there's no app switching going on when you hit 'subscribe' in the example app I suspect it's also not a url scheme.
Who knows?
Try something like this:
NSString *url = #"http://server/filename.ics";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
This shows an uialertview with the question to the user if he/she wants to subscribe.
;)

Loading images from to differenet base resources to the webview

I am implementing a WebView in which I need to use some images. For this, I use the images under the ressources folder and call
[myWebView loadHTMLString:returnString baseURL:[[NSBundle mainBundle] resourceURL]];
It is working fine. In the same time I need to use some external images coming from the server in the same WebView. For this I need to change the baseURL of the target server but I don't know how to handle these two.
How to handle both images, from local and external server in one HTML?
If you use full URLs (i.e. http://www.exmaple.com/myimage.png) for the images coming from the server, they won't be affected by the baseURL parameter, which is only used for resolving relative (partial) URLs.
I think you can create two instance of UIView class and add the UIWebView in both the views.
In the first webview show the image from the resource and in the other webview show the image from the server.
Just give it a try see if this works.