Determine the time period of when my app was purchased - iphone

Is there a way (in code) that you can give an app different features based on when it was purchased??
I have people who have bought my app for a different price and some had it free during a promotion.
It would be nice to give a little thank you with an extra feature in my app for the ones who paid for it.
Is that in anyway possible?

Without having it in place beforehand, you won't ever know about the past, but nothing prevents you from putting the timestamp of when a user first opened your app into e.g. the user settings. Something like
[[NSUserDefaults standardUserDefaults]
setObject:[NSDate date]
forKey:#"install_date"];
which you could then use to decide how to "treat" (I guess) the user. The one catch is that if a user ever deletes the app and then reinstalls it, their early adopter bonus or whatever will be lost. The only other option you have is to send the device ID to a dedicated server somewhere, e.g. a PHP script with a simple MySQL db where device id's are stored along with dates. You could then do something like
NSDate *purchaseDate = [[NSUserDefaults standardUserDefaults]
objectForKey:#"purchase_date"];
if (nil == purchaseDate) {
// we need to get the date for this user from the server, or
// we need to register the user as it's the first time
} else {
// we know when this user installed the app, and they did so
// (approximately) at the purchaseDate time.
}
Date format issues aside, the above should be pretty straightforward, but as said, does require a server somewhere (which can be a slow mo because the above only happens on first install and reinstalls).
Edit: you can use [[UIDevice currentDevice] uniqueIdentifier] (deprecated as of iOS 5) or [[UIDevice currentDevice] identifierForVendor] (new as of iOS 6.. lol) to get the device ID.

You have to manage it by code officially Apple don't provide any code for that. But if in case you need any kind of analysis of app. Like , which part of app was used by user, which part makes crash of app, something kind of feature you can try this Flurry Analytics for it .

There is no way to detect from within your app when an app has been purchased. You could add detection of when it was installed, but that could have happened at any later time, even multiple times.

Related

How to get application installation time in iPhone

Is there any way to get application insatllation time in iPhone? I wanted to use this information as a unique identifier, can I use it for this purpose?
There is no way to get the application installation time.. You can keep track of the first launch of your application within your application using NSUserDefault.
In application didFinishLaunchingWithOptions: you could do
NSDate *date =[[NSUserDefaults standardUserDefaults]objectForKey:#"FirstLaunchTime"];
if (date == nil) {
// nil means your application running for the first time
[[NSUserDefaults standardUserDefaults]setObject:[NSDate date] forKey:#"FirstLaunchTime"]; // set the current time
}
NO. You don't know anything about the actual installation (duration / time) within your app. You only know the first start date.
For unique IDs, check this answer:
How to get the UDID in iOS 6 and iOS 7
You can have a field in user setting for this and when user installs and opens it you will get a callback in appDelegate's didFinishLaunching method.
Here you can check if the particular field is nil then only store current date time. You can use this date time in your app.
What you could do is check the /Documents directory to see if there's anything it when it is first run (there shouldn't be if it's the first time it's been installed on that device). If not, write a file there with the current time stamp.
I guess you could use this information as a unique identifier, but in theory, there could be multiple people who open the app for the first time, at the same time. I wouldn't do it.

MKStoreKit Buy Feature does nothing

I'm trying to get the MKStoreKit working with my Cocos2D game. It look pretty simple to do and I've followed all the steps a couple of times (to check I've done it correctly) but I still can't get it to work. I can retrieve a product name, price and description etc. but I can use the shared MKStoreKitManager to make a purchase.
Here's my code for buying a product:
if([MKStoreManager isFeaturePurchased: #"com.testing.iap.removeAds"]) {
NSLog(#"No ads");
}else{
NSLog(#"Ads");
NSLog(#"Buying feature...");
[[MKStoreManager sharedManager] buyFeature: #"com.testing.iap.removeAds"
onComplete:^(NSString* purchasedFeature)
{
NSLog(#"Purchased: %#", purchasedFeature);
// provide your product to the user here.
// if it's a subscription, allow user to use now.
// remembering this purchase is taken care of by MKStoreKit.
}
onCancelled:^
{
NSLog(#"Something went wrong");
// User cancels the transaction, you can log this using any analytics software like Flurry.
}];
}
Basically if the product hasn't been previously purchased, kick off the purchase process. The problem is nothing happens! I don't even get the onCancelled being called and there are no error messages apart from the one's I can ignore (i.e. iCloud support and custom server options).
Can anyone shed some light on what it is thats stopping me?
Note: I'm testing on an iPhone 4 device running iOS 5.1
As soon as your app launches, call:
[MKStoreManager sharedManager];
That's it. As long as you call the -buyFeature: method after the products have been downloaded (you could observe kProductFetchedNotification if you want) everything works as expected.
I have no idea what wasn't working but after spending al most a full working day trying to get this to work I decided to start a new project from scratch and try again. I done everything exactly the same and it all worked!
Make sure you added your IAP key to the MKStoreKitConfigs.plist. Without that it does nothing.
Also it can take a few hours until a register IAP becomes available for testing.

saving current date and time in my iPhone application?

In my application i am using In - App purchases to provide a subscription of 1 year….now i need to save the time and date when the user buys the subscription and need to check when the subscription expires?? i have not used database before is there any other way to store date and time in my application and retrieve it every time the application starts??
You should store the purchase of a subscription on a server, with backup in place, not only on the device.
You might have noticed that if you delete any iPhone app, and later re-install it, then the next download is free. There can be many reasons as to why the user might loose your app, a system update went bad, or whatever.
Apple specifically requires that the user do not loose what they have bought. If you have promised 1 year, then you must make sure they get 1 year no matter what happens to your app. Otherwise Apple can, and will, reject your app.
Storing the expiration date on a server also give the added benefit of protection against users fiddling with your data and granting themselves extended subscriptions.
Start by looking at the In App Purchase Programming Guide.
You can simply store it in NSUserDefaults:
[[NSUserDefaults standardUserDefaults] setObject:[NSDate now] forKey:#"purchaseDate"];
Then retrieve it like such:
NSDate *purchaseDate = [[NSUserDefaults standardUserDefaults] objectForKey:#"purchaseDate"];
And when you're done with it:
[[NSUserDefaults standardUserDefaults] removeObjectForKey:#"purchaseDate"];

how to get Iphone UDID of device while installing the application from app store?

In my Iphone application , i am able to get the UDID of the device and have display it on alertview.
my query is that while any user go to the apple appstore and try to istall the application, at that same time how to get the UDID of the device and store it to the Database and also want the UDID of application at the time of uninstallation.
Whether is it possible or not?
If possible please provide any code or any useful link or any other info,which would be appreciated.
Thanks,
Mishal Shah
You can't run any process when your application is not actually running - this includes at download time and at uninstallation.
Instead, you should try to find other ways to measure what you want. You can, for example, have your application keep track (in NSUserDefaults or similar) of whether or not this is the first time the user has launched your app, and if it is submit the UDID to your server.
Tracking uninstallation is a lot harder - the best you may be able to do is to keep track of how long it's been since the user last launched your app (if you have the app submit a launch time every time the user opens it).
Keep in mind that a lot of tech-savvy users will object to your gathering the UDID or usage patterns within your app without their express permission (or at all).

Unique identifier for an iPhone app

For an iPhone app that submits images to a server I need somehow to tie all the images from a particular phone together. With every submit I'd like to send some unique phone id. Looked at
[[UIDevice mainDevice] uniqueIdentifier]
and
[[NSUserDefaults standardDefaults] stringForKey:#"SBFormattedPhoneNumber"]
but getting errors in the simulator.
Is there an Apple sanctioned way of doing this?
What errors are you getting? [[UIDevice currentDevice] uniqueIdentifier] (edited to fix API, thanks Martin!) is the officially recommended way of doing this.
You can also use CFUUID to generate a UUID. Here's some code:
NSString *uuid = nil;
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID));
[uuid autorelease];
CFRelease(theUUID);
}
By far the easiest and most appropriate way to obtain a unique identifier is to use the mechanisms Apple explicitly provides for obtaining one - [[UIDevice currentDevice] uniqueIdentifier]. You can not guarantee that the phone number will be unique to the device or that the device will even have a phone number. Beyond that, doing so is a horrible idea as it is a definite invasion of the user's privacy. Even the uniqueidentifier should be hashed if you are going to store it in any way.
In order to Persist the Unique Identifier you create between installations, you could use the Keychain Made easy with SSKeychain: Simply set your UUID as follows:
[SSKeychain setPassword:#"Your UUID" forService:#"com.yourapp.yourcompany" account:#"user"];
and then call it again anytime you need it:
NSString *retrieveuuid = [SSKeychain passwordForService:#"com.yourapp.yourcompany" account:#"user"];
Note: The services and accounts must match exactly.
Then, if the App is deleted and reinstalled, the UUID will persist with reinstallation.
If you then want to share this UUID across devices, set up your app to use iCloud. You can then store the UUID in NSUserDefaults, sync with KeyValueStore, and then set the UUID in the new devices keychain with the code above.
This answer would get extremely long if I typed code for all the above, but plenty of sample code around here to figure it all out.
Don't forget that in iOS 5 uniqueIdentifier will be deprecated you should use CFUUID instead of that
Interestingly, Apple has since deprecated the uniqueIdentifier in iOS 5 (as gN0Me mentioned). Here's the relevant TechCrunch article:
http://techcrunch.com/2011/08/19/apple-ios-5-phasing-out-udid/
Apple suggests that you no longer uniquely identify the device but instead identify the user. In most cases, this is excellent advice though there are some situations which still require a globally unique device ID. These scenarios are quite common in advertising. Hence, I wrote an extremely simple drop-in library which replicates the existing behavior exactly.
In a shameless plug of self promotion, I'll link it here in the hope that someone finds it useful. Also, I welcome all and any feedback/criticism:
http://www.binpress.com/app/myid/591
Nevertheless, in your particular situation I would advise skipping the globally unique ID functionality my library provides as it's a bit overkill for your situation. Instead, I would generate a simple CFUUID and store it in NSUserDefaults. This ID would be specific to your application but would allow you to group all the photos for that "app install" in your database.
In other words, by deprecating the uniqueIdentifier method, Apple is suggesting that you don't identify per device but instead per app install. Unless you are operating under specific conditions, chances are the per app ID fits your product better anyway.
This is an interesting problem that I am also looking into solving. Here is a scenario that I would like to address.
What happens when you sell your phone to another person... that Device ID will then belong to somebody else, so even if the app is removed from the iPhone, it could be re-added and all that data would then be re-associated to a new user... this is bad.
Using the Phone number with the Device ID MD5 would be a great solution. Another we came up with is having a SQL Lite DB with some token Hashed with the Device ID. Then when the app is removed the DB is killed and all the data is disassociated. I think that might be too brittle.
Any other ideas?
Rob Ellis (PhoneGap/Nitobi)
Use Apple's GenericKeyChain which is the best solution . Here is the working sample >>https://developer.apple.com/library/prerelease/ios/samplecode/GenericKeychain/Introduction/Intro.html
Have idea about KeyChainAccess >>https://developer.apple.com/library/mac/documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html#//apple_ref/doc/uid/TP30000897-CH204-TP9
Haven't done iphone work, but how about taking a hash of something unique to the phone ... oh, say the phone number?
Getting iphone number
snippit:
NSString *phoneNumber = (NSString *) [[NSUserDefaults standardUserDefaults] objectForKey:#"SBFormattedPhoneNumber"]; // Will return null in simulator!
NSLog(#"Formatted phone number [%#]", phoneNumber);
I [recently] ran this code as-is on OS 2.2.1 [and OS 3.0].
It works as expected when run on the device, and returns my phone number with the full international dialing codes [ 1 in my case].
When run on the simulator, the value [returned] is a null string, so it only works on an actual iPhone device.
I did not test it on an iPod Touch.
...
Ran this code on a different device this week, and got a null value instead of the number.
On further research, it appears that the number returned by this code snippit is the number that is set up in iTunes for the device.
If you didn’t enter the iPhone’s number in iTunes at device activation, or perhaps (as in my case) if the default value wasn’t the iPhone’s number and you clicked OK anyway, such that iTunes doesn’t list the phone number when your iPhone is plugged in, this code will return a null string.
[Above is an edited concatenation of comments I recently posted to another article on this topic at http://www.alexcurylo.com/blog/2008/11/15/snippet-phone-number/]
Here is some more information on a way to get it from iTunes which may be useful for testing purposes.
I had success with such code:
- (NSString *)stringUniqueID {
NSString * result;
CFUUIDRef uuid;
CFStringRef uuidStr;
uuid = CFUUIDCreate(NULL);
assert(uuid != NULL);
uuidStr = CFUUIDCreateString(NULL, uuid);
assert(uuidStr != NULL);
result = [NSString stringWithFormat:#"%#", uuidStr];
assert(result != nil);
NSLog(#"UNIQUE ID %#", result);
CFRelease(uuidStr);
CFRelease(uuid);
return result;
}
You can use MAC address as a unique id. Following link will help you
How can I programmatically get the MAC address of an iphone