Programmatically retrieve list of installed apps that support a given file type - iphone

While it is clear we cannot retrieve a list of installed applications on iOS, are there any tricks to allow us to determine the list of apps registered for a given file type? That is, the list the user will see in the Open In... menu for that particular file type. canOpenURL only returns a boolean, but ideally it would return us a list of supported installed applications.

Open in is certainly possible by the UIDocumentInteractionController You just need to instantiate UIDocumentInteractionController instance:
//Following in header file:
UIDocumentInteractionController *docInteractionController;
Implement the delegate:
<UIDocumentInteractionControllerDelegate>
.m:
//Here the url is the document URL that you want to open (or you want to apply open in functionality)
self.docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docInteractionController.delegate = self;
Open In method will be like following:
- (void) openIn: (id) sender {
[self.docInteractionController presentOptionsMenuFromBarButtonItem:sender animated:YES];
}
and once you are done:
[self.docInteractionController dismissMenuAnimated:YES];
and that's it. This will list down the list of application supported for document and on selection of them will launch the corresponding application with the document URL we instantiated with.

I doubt either of your two questions ("determine list of apps for a given file type" or "how to implement 'open in...'") is possible in current versions of iOS as users don't see individual files on the home screens that show apps. Nor can an app do a "open a separate app with this specific file" event (which is something easily doable on a Macintosh with Apple Events).
But these do sound like a great feature requests that you can file with Apple at http://bugreporter.apple.com (which you can log into, if you're a registered Apple developers). If enough people ask for these features (and the potential "open in..." functionality is indeed a frequently requested feature), Apple will strongly consider including them in future iOS releases.

You can see this sample program. It might help you. It has used UIDocumentaInteractionController class instance with its property UTI (Unique Type Identifier). It helps in retreving list of installed apps on your phone that support the file type you have opened in your app. You might need to rewrite the UTI property a little bit as per your convience
http://developer.apple.com/library/ios/#samplecode/DocInteraction/Introduction/Intro.html

Related

Create an App within an App

I am being presented with a very interesting project. The task that I must complete is to figure out a way to allow a partner to be involved in an app without giving up their source code. The code will be included in the main bundle of the app so it is not dynamically stored. The partner has a fully functional app that is needed to be ran in a window within the main app at the appropriate time. I know having the partners create a web app would be ideal so it is treated like a webpage but I am more concerned with codes that must be written natively in iOS.
My question is what is the best way to go about solving this? In theory it is like an App within an App. Is there a way if they gave up their .app file I can include this in the bundle and then run it when I catch a certain event? Should I have the partners create their code in a framework and then import into the shell project? What is the best way to approach this problem?
If your 2nd-party doesn't want to provide you with the source code, why doesn't he compile it to object code then let you simply link it to your app?
By the way, at least on official (non-jailbroken) iDevices, apps can't 'embed' or 'open' one another in such a way - you can open an app programmatically if 1. it's a separate app 2. it has a registered special URL associated to its bundle.
Is there a way if they gave up their .app file I can include this in
the bundle and then run it when I catch a certain event?
No, you'll want to have them create a library instead. You can then include that library in your project.
Creating a library is as simple as:
Choose File->New...->Project... in Xcode.
Select the "Cocoa Touch Static Library" project template.
Add your code.
Build.
The result is a static library that you can add to your application(s). The library will contain the compiled code that you added, but doesn't include the source code. The library developer should provide whatever header files are necessary to use the code in the library.
An App within an App is possible however it requires a common data framework that allows one app to reference the same data without confusing the the source of and destination of the data.
Such a framework allows one app to interact with another app referencing the same data.

iPhone Dev - Creating a one time UIAlertView like in Temple Run

You know how Temple Run sometimes has alerts when you open the App that appear even though you don't update the App? I understand how you would implement this if you were to submit an update to your App, but how does Imangi implement new alerts without releasing new versions of the App? (I'm assuming they upload it from some server, but I'm an amateur at all of that stuff so could someone sorta vaguely explain how I might go about doing that? Will I need to learn Internet programming languages :O?)
Thanks.
I agree with Jonathan. I would set a plist with a reference number on your server. and it would look something like this. I'm using concept, not code. It would be as simple as hosting it on your server. Or it could be as complicated as your creating a user interface on your website that allows you to just plug in the information and it would create the plist for you.
-(void)checkanddisplaynotificationbasedonupdatedplistontheserver{
int currentnotificationnumber = userprefs preference for item "notification"
get and parse notification.plist from your server
notificationnumber = object at index 0
if notificationnumber > currentnotificationnumber{
display your notification with parsed plist
}
}
You could host a plist online, with an array of alerts stored as dictionaries, with attributes like 'title', 'body' etc. The app would then parse this and to create an alert. You could then set up a method which searches for updates to this file every time the app opens and has connectivity.
This is not the only way - there are probably hundreds of other files types/ automated systems to use, however this is a simple way, and roughly how all of them work, and I have implemented something like this in some of my apps. Hope this helps, if you wan't any help coding it, I will be happy to help!
Jonathan

when and how to detect an iCloud conflict?

I use iCloud to sync an user xml file between devices in my apps, with a UIDocument subclass, similar to the code from the question:http://stackoverflow.com/questions/7795629/icloud-basics-and-code-sample. but I am not sure when and how should I detect a conflict. I read the sdk doc and searched the internet but didn't seem to find any information with detailed information. it seems we can use some code like
NSNumber* conflicted ;
[url getResourceValue:&conflicted forKey:NSURLUbiquitousItemHasUnresolvedConflictsKey error:nil];
but in my app, it seems always give a true value for "conflicted"?
also I am not sure when should I detect the conflict, my guess is before the contentsForType method of the UIDocument subclass is called. if anyone can give any hint that would be great.
You should observe the UIDocumentStateChangedNotification. If the documentState property of your document has the UIDocumentStateInConflict flag set, there is a conflict. Note that a document can be in multiple states simultaneously, so don't check with ==, instead use something like if (document.state & UIDocumentStateInConflict) {....
You can then get the conflicting versions with the otherVersionsOfItemAtURL: class method of NSFileVersion.
You can find more detailed information in the chapter on resolving document conflicts in the Document-Based App Programming Guide for iOS.

Register for all file types (CFBundleDocumentTypes)

Programs like Drop Box, or Airsharing don't handle or edit documents but store them. In this case it would seem that they have to register as being a valid choice for any type of file. Is there a way to register your application as a handler for all files? '.*' ? Or is the only solution to register for any type of file that you can think of?
Registering for the public.data type accepts EVERYTHING. If you want specific actions for certain types of files you will need to check when it gets passed to your app. See this apple doc for the hierarchy: Apple
Edit for clarification: public.data allows for your app to accept any kind of data type. (image/text/etc..)..the very base UTI is public.item (includes public.data and public.content and public.archive). As i'm not sure what you are really trying to do, it could be that you want the other stuff as well.

Can I change the Core Location alert message when accessing ALAssets?

I am using the ALAssets framework to access the Photo Library. The first time it's accessed, it asks the User if the app can use their Current Location, and I understand that is necessary and why.
However, in Core Location Manager, there is a purpose property, where it looks like I can customize the iPad's alert message to say why it is necessary to tap Yes. (I don't actually use location, just want access to the photo library.)
I can't seem to work out how to find out where to use this property, as the alert message comes up when I first try and enumerate the assets, and there doesn't seem to be anywhere to intercept it before the error occurs if the user says NO.
I know I can put up a notice of my own before first usage of ALAssets, in anticipation of the iPad built-in alert, but it seems slicker to change the actual iPad message.
Thanks.
I’d suggest, before you try to access the photo library, that you create your own dummy CLLocationManager, set its purpose, then call its -startUpdatingLocation. That’ll get the system to bring up the location permissions dialog with your custom text, and the resulting app-wide location permissions ought to carry over to your ALAsset access.
Unfortunately you can't customize this message. I suggest you will a radar with Apple, if you want to see this feature in the future.
Cheers,
Hendrik