How to figure out the app ID programmatically at runtime? - iphone

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

Related

Path of the ios application on device

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!! :]

How to create Unique Identifier and save it to identify user(device)

I want to create unique identifier on iOS 5 and use it for identifying user (user device) every time app is started. I am able to create a unique identifier by following code
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
But unable to save it on user device so that particular identifier is not deleted even when app is uninstalled. I tried using SSKeychain approach but it gives Apple Mach-o Linker error.
Please let me know the the way I can accomplish the same.
Any help is appreciated.
I had exactly the same problem after adding SSKeyChain to my project following the author's instructions online. I eventually discovered that the implementation file was not included in my list of source files in build phases. To rectify the issue do the following:
1) Select your project, then its target.
2) Then select the Build Phases tab
3) On the Build Phases tab you will see a group called Compile Sources, expand it to view contents
4) Check to see if SSKeyChain is in the list
5) If not (as in my case) click the little plus sign at the bottom of the group and navigate to where you added SSKeyChain.m and add it.
Build your project and the error should have disappeared...
I hope this helps!

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.

Change an App Setting when updating the iPhone application to a new Version

I want to change the URL that my application connects to, to a new sever. The problem is, the URL value is saved in a settings file. When I update the application to the new version, the old file is read from the device, and overwrites my settings. What I want is to use the new URL the first time the updated version is launched. After that, I am happy to read the URL from the file.
Is there any way I can determine this is the first time after an update when I lauch the application?
Thanks!
As another user, you can get the current version by reading the CFBundleVersion of your app's bundle. The problem with this approach is that a user might not install "version 1" of your app. Instead, I suggest putting something like the following in your app's didFinishLaunching method:
#define kSettings [NSUserDefaults standardUserDefaults];
if(![kSettings objectforKey:#"isFirstRun"]){
// You could check the version here
// and do some initial setting up.
[kSettings setBool:NO forKey:#"isFirstRun"];
}
Then, for each subsequent version, you can add another if block with another flag to check for that version, like so:
if(![kSettings objectForKey:#"isFirstRunForVersionX"]){
// Do some version specific set up here.
[kSettings setBool:NO forKey:#"isFirstRunForVersionX"];
}
I've successfully used this approach in several of my apps.
To determine it it's the first launch after the update, you could retrieve the version number with this piece of code:
NSString* v = [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleVersion"];
And compare it to a previous value you have saved.
You can store flag in NSUSerDefault. So You need to check first time if isFirstTime==0 then do your code and make isFirstTime=1; So it only runs first time.

How to share keychain data between iOS applications

I am describing a problem for which it took me quite some time to learn the answer.
The "GenericKeychain" example is a good start at providing a wrapper for sharing keychain data between applications when using the accessGroup in the init.
However, implementing this in my app yielded an obscure error code (which took forever to locate) -25243, which means: No access control.
I ran Apple's example app (GenericKeychain) on my iPad only to get the same error. Huh?
Does Apple's documentation fail to deliver on what is necessary to accomplish this?
After some (a lot of) digging throughout the web, I found the answer. The access Group that you use when constructing your KeychainItemWrapper class must ALSO be specified in each of your application's Entitlements.plist file in the "keychain-access-groups" section.
It seems almost obvious now that I see "keychain-access-groups". However, I had no idea to even look there. Hope this helps others.
Actually it's not hard to do. Please follow the steps.
App1:
Open your App's target Capabilities and enable KeyChain Sharing.
Add a identifier. (eg : com.example.sharedaccess)
Add "UICKeyChainStore" to your project.
Be sure you have a team id added to your App1 project.
Add Security.framework to your App1 project.
And add these codes to somewhere you need.
[UICKeyChainStore setString:#"someValue" forKey:#"someKey" service:#"someService"];
App2:
Open your App's target Capabilities and enable KeyChain Sharing.
Add a identifier. (eg : com.example.sharedaccess)
Add "UICKeyChainStore" to your project.
Be sure you have a team id added to your App2 project.
Add Security.framework to your App2 project.
And add these codes to somewhere you need.
NSString *string = [UICKeyChainStore stringForKey:#"someKey" service:#"someService"];
Your TeamIDs should be same for both projects.
I tried these steps on a real iPhone device.
I also tried these steps with Automatic and iOs Development provisioning profile.
My apps' bundle identifiers were like that : com.example.app1, com.example.app2.