Path of the ios application on device - iphone

Well, I would just like to know is it possible to know the path of the app? I used the following code
[NSBundle mainBundle] executablePath];
It retrieved the below value. That is correct.
/var/mobile/Applications/FBE187F1-256D-495D-852B-53AECD4F4C23/Test_Data_Fetch.app
And I would like to know, is it possible to check the existence of other app? The problem is FBE187F1-256D-495D-852B-53AECD4F4C23 this particular directory value changes for every app. I would really like to know if it is possible!!

Your application cannot access anything outside sandbox so you can't search file system directly for a given application.
One possible solution is if application you are interested in handles custom url scheme, then you can check if that url scheme can be opened:
NSURL *url = [NSURL URLWithString:customScheme];
BOOL appProbablyExists = [[UIApplication sharedApplication] canOpenURL:url];
Update: This article describes several possible approaches, but it seems there's no definite way to get list of installed applications using public API

Finally, using the Mac program iExplorer we can look at any App’s data. This is not related to my question, though it is quiet useful!! Was able to achieve my goal!! :]

Related

Pass NSDictionary or a String from one App to another App iPhone

I have to send data which is present in an dictionary from one application to another application, which has to used over there.
Please help.
I am not exactly sure about how to do it but I think you might need to use the Custom URL Schemes for that. Here is a link that can help you register your URL Scheme and then using it.
At least you can pass it as a string parameter of custom url (like thesecondapp://data_string_goes_here) and then parse it from within the app you pass it to
See how to encode NSData to NSString here.
EDIT: You should also take a look at application:openURL:sourceApplication:annotation: method implementation examples. It could be a bit more sophisticated but it seems to be more 'native' than just passing a raw string.
Here is the info how to call the 'counterpart' of this method from another app.

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

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

iOS basic FTP setup; Read and Write Stream

I'm attempting to create an iOS 5 app with some very basic FTP functionality and need some guidance. It will be connecting to a device on a local network and performing read/write actions with .dat/txt files. I've done some searching for the past few days and have seen various recommendations but nothing simple enough that I can pick up and quickly modify for my personal use.
My questions are these:
Are there any tutorials/sample code that you could recommend to me?
What frameworks and classes should I be working with for basic read/write operations?
Lastly, I should mention that I have given a considerable amount of time to analyzing the SimpleFTPSample from Apple but the sample code is giving "Connection Failure" and "Stream Open Error" notices for each example, so I'm a bit wary of its usefulness.
Forgive me if this has been answered elsewhere. All of the related posts have pieces of the answer I need, but not the whole thing. Thank you in advance!
EDIT for clarity: A well-defined example or step-by-step tutorial is what I would really like. My own Google searches have turned up nothing and I am desperately in need of some guidance here.
UPDATE:
I posted this question long ago but have continued using the FTPHelper mentioned in the accepted answer. I recently brushed the dust off the old project and realized there was a minor memory leak in FTPHelper's fetch function that can be an app-killer if called repeatedly. If anybdy stumbles across this question and chooses to use FTPHelper, be sure to add the CFRelease line seen in the code below.
- (void) fetch: (NSString *) anItem
{
if (!self.uname || !self.pword) COMPLAIN_AND_BAIL(#"Please set user name and password first");
if (!self.urlString) COMPLAIN_AND_BAIL(#"Please set URL string first");
NSString *ftpRequest = [NSString stringWithFormat:#"%#/%#", self.urlString, [anItem stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
/* CFShow(ftpRequest); */
NSString *writepath = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
self.filePath = [writepath stringByAppendingPathComponent:anItem];
CFURLRef writeURL = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8 *) [writepath UTF8String], [writepath length], NO);
MySimpleDownload((CFStringRef)ftpRequest, writeURL, (CFStringRef) self.uname, (CFStringRef)self.pword);
CFRelease(writeURL);//ADD THIS LINE TO FIX MEMORY LEAK
}
The SimpleFTPSample app is running perfect, probably there is an issue that you can't see. What I can recommend you (except Apple's example) is to check THIS example which contains a helper class for all basic FTP operations. One thing to be aware of is iOS 5 ARC. Both Apple's example and the one I linked are for older iOS versions.
There are basically 2 ways to use them in iOS 5 - by telling the compiler to not use ARC by adding -fno-objc-arc flag in [Your project] -> TARGETS -> [Your app] -> Build Phases -> Compile Sources -> [Your file], or by using the built-in tool in Xcode for converting to ARC.
I personally have tested only the first method and it works for me.
If this does not help you I can write an example, but unfortunately today I am very busy.
UPDATED:
The basic mechanism is to use [FTPHelper list:THE_FTP_URL] to list the content of a folder, then create one list with the content and depending on the type (file or folder) download using [FTPHelper download: THE_FTP_URL_WITH_THE_FILENAME_FROM_LISTING]. From here you have to implement
- (void) downloadFinished
{
//do the reading depending on the file type
NSData *data = [NSData dataWithContentsOfFile:[FTPHelper sharedInstance].filePath];
}
The uploading is achieved in a similar way - using [FTPHelper upload:FILE_TO_UPLOAD] with a file from the filesystem.
There are many libraries which you could use and they are working great. :)
For example:
http://www.chilkatsoft.com/ftp-objc.asp
http://code.google.com/p/ios-ftp-server/
I recommend using them, because coding one by yourself would take a lot of time :)
One thing to remember, as o15a3d4l11s2 said, is to be aware of ARC. If you use it don't forget to add build flags to libraries which aren't ARC.

iOS:How to get current application language

The application that I'm working on supports 3 languages: English, French and German.
How I can get the current application language (NOT the device language)?
The problem is that I have to get the current language of the application in order to send it with a request to the server and the respond should be in the right language. The device language is useless because if the user switch the os language to Italian, the app is running in English and I need to send english to the server.
Thanks
The accepted answer is a workaround.
Regarding language preferences in the device itself, you have the
[NSLocale preferredLanguages]
which will give you an ordered array of the preferred languages as defined in the system's General Settings.
The Cocoa Touch framework will take this list of preferred languages into account when loading the app's localization resources and filter it according to the translations you provide in the bundle.
This filtered and ordered list of localized languages can be obtained with
[[NSBundle mainBundle] preferredLocalizations]
Your server requests should match the first value in this array or you will have a language mismatch between app and server data.
What i always do:
Add a string entry into the Localizable.strings files.
I always use the key "lang"="de"; (or "lang"="en", etc.).
Then you can use it in your NSURLRequest by adding the language over NSLocalizedString(#"lang", #"")
With that method you have absolute control what is going to be sent to you backend.
You may use the preferredLocalizations method of the NSBundle class:
NSString *currentLocalization = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
Since iOS 13 the language can be set for each app individually.
In the session "Creating Great Localized Experiences with Xcode 11" at WWDC19 they showed two options for determining the user settings for the application.
Get the currently running application language:
Bundle.main.preferredLocalizations.first
Get the best language, given an external language code list:
let availableLanguages = Server.requestLanguages()
Bundle.preferredLocalizations(from: availableLanguages).first
The app language will change when the user change the device language and you can get it from the NSUserDefaults (i will show you how if you want to ) unless there are an option to change the language inside the app then you can easy save the current used language and send it to the server when ever you want.

How to figure out the app ID programmatically at runtime?

Is there a way to do that? I would hate it to hard-code the app ID somewhere...
If you mean your com.whatever.whatever identification:
NSString *myAppID = [[NSBundle mainBundle] bundleIdentifier];
If you mean your iTunes id123456789 identification, it's not available to you at runtime, but is given to you on iTunes Connect and can be manually inserted into your app from there.
No way to do this. I think you are probably trying to link to your product page right? Try the link method using your name of your app
http://itunes.com/apps/<YOUR APP NAME>
Try it
try reference THIS on
developer.apple.com. (need account on developer appleID)
U can use like below.
add AVFoundation.Framework to your Project.
import header "AVFoundation/AVFoundation.h"
U can use constants below.
NSString *const AVMetadataiTunesMetadataKeyAppleID;
the code snippet provided in this question shows how to pull out the bundle seed ID via code:
https://stackoverflow.com/a/11841898/931658