NSUserDefaults boolForKey strange behaviour on real phone - iphone

My application is approved and ready to sale in appstore today. I downloaded it from appstore immediately but when I open my application there is no ads in my application. I dont understand anything.
In my code if user buy inapp item I set the value of userdefault to TRUE.
So when application starts Im checking this userdefaults. If it is TRUE I dont show any ads , if not I call ads api.
this is part of inapp purchasing area :
if ([productId isEqualToString:#"dontshowads"])
{
//user bought inapp item. so I must remove advertorials.
[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:#"aldimi_lite_reklamikaldirma_099"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
and this is viewwillappear area :
BOOL appin_reklamkaldirmaalindimi = [[NSUserDefaults standardUserDefaults] boolForKey:#"aldimi_lite_reklamikaldirma_099"];
NSLog(#"appin_reklamkaldirmaalindimi :%d",appin_reklamkaldirmaalindimi);
if (!appin_reklamkaldirmaalindimi)
{
NSLog(#"showing ads");
}
else {
NSLog(#"no ads. user bought inapp item");
}
When I run my application in simulator everything is fine. (I deleted it first in simulator and re build it)
Console gives this logs:
appin_reklamkaldirmaalindimi : 0
showing ads
When I run my application in my real phone everything is fine also. (I deleted it first in my phone and re build it)
Console gives this logs:
appin_reklamkaldirmaalindimi : 0
showing ads
But when I run my application which is downloaded from appstore everything is different.
Console gives this logs:
appin_reklamkaldirmaalindimi : 0
no ads. user bought inapp item
I tried to download and check the situation in my friends phone . Everything is the same. So it is not about my phone.
how can it possible ? I thought one hour and I cant find any explanation to this situation ...

The only explanation for such a weird phenomenon is that the code which you submitted to the App Store is in some way corrupted or different than the code which you tested by building off your computer. The only way to fix this problem would be to resubmit your application to the App Store.
The only other possibility I can think of is that your app has some VERY poor and incorrect memory-access tendencies, such that part of your executable code or stack somehow gets over-written before running your ad logic.

Related

In-App Purchase doesn't work

I want to add in-app purchases to my app, but I can't make it work. I'm using MKStoreKit 4.2.
Here is the buying code:
- (IBAction)onPayButtonPressed:(id)sender {
[[MKStoreManager sharedManager] buyFeature:#"com.flowrower.TestApp.0.99.item"
onComplete:^(NSString* purchasedFeature, NSData* receiptData)
{
NSLog(#"Purchased: %#", purchasedFeature);
}
onCancelled:^
{
NSLog(#"Cancelled");
}];
NSLog (#"END");
}
In output I'm always getting "END" only. So buyFeature doesn't work at all.
Testing on iPhone 4S with iOS 6.0.
Using Provision Profile with In-App Purchases support.
There is Product ID "com.flowrower.TestApp.0.99.item" in iTunes Connect with status "Ready to submit"
This product is consumble and I have added it to MKSoreKitConfigs.plist
Everything's OK with Contacts, Bank and Taxes in iTunes Connect
Logged off from iTunes and App Store on my device.
Getting this message at app start: "NSUbiquitousKeyValueStore error: user.TestApp has no valid com.apple.developer.ubiquity-kvstore-identifier entitlement". I don't know is it related or not.
if its not approved, you need to test in the sandbox. I don't know MKStoreKit but I think you need an adhoc certificate!?
The problem was with iOS 6. 12 days ago new version of MKStoreKit released and it work like a charm in iOS 6. Thanks guys.

MKStoreKit not storing purchased Products

I'm using MKStoreKit to implement an IAP into my application. Everything does as expected when purchasing the product, no error messages at all. The product is purchased using the following code..
[[MKStoreManager sharedManager] buyFeature:#"pro_upgrade"
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:^
{
// User cancels the transaction, you can log this using any analytics software like Flurry.
}];
After the product has been purchased I recieve the notification (via the code below) which confirms the purchase..
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector (subscriptionPurchased:)
name: kSubscriptionsPurchasedNotification
object:nil];
After the purchase I execute the following code (as documented) to determine if the product has been purchased..
if([MKStoreManager isFeaturePurchased:#"pro_upgrade"]) {
NSLog(#"This feature is purchased.");
} else {
NSLog(#"This feature is not purchased");
}
It constantly returns NO for the product ID. This happens when running the app in the same instance as when the product was purchased as well as closing the app and opening it. Running the app using Development or Distribution certificates make no difference at all. Further more I can't find where exactly MKStoreKit stores the product purchased BOOL that it seems to be looking for (it's pretty deep in the code so i'm not saying it does or doesn't, i just can't find it). My app is storing other information using NSUserDefaults so that isn't the issue.
Any help you can offer will be extremely appreciated, thanks for your time.
MKStoreKit doesn't store in NSUserDefaults.
I use keychain instead. Place a breakpoint in the method
storeData:forKey: (writing this method name straight from my head
without looking at code, search for similarly named methods) and try
debugging it. This is the place I save your purchases.
Do remember that purchases are remembered even after deleting and
reinstalling the app.

Check if app has been purchased

I am a beginner; I am trying to solve this but am unable to do so.
I have created an app that displays a few options in a table. When the user taps the cell the details of selected option is shown on another page (details are stored in a plist file).
What I want to do is to set it up so that if the user has purchased the app then only the details should be visible, but if the user has not purchased it, the user should be prompted to do so.
I have created a product ID for iTunes Connect and also created a testing account to test the app.
My problem is with the code: how should i check if user has already made the purchase?
Using NSUserDefaults is the easiest solution.
After a successful purchase:
[[NSUserDefaults standardUserDefaults]
setObject:#"purchased"
forKey:#"myPaidItem"];
[[NSUserDefaults standardUserDefaults]
synchronize];
And when you need to check if the user has purchased the item:
NSString* isPurchased =
[[NSUserDefaults standardUserDefaults]
stringForKey:#"myPaidItem"];
if ([#"purchased"
compare:isPurchased]==NSOrderedSame) {
........ }
Hope that helps
you have to store this information in appContext as a bool if the transaction is OK , boo= true
and when he want to buy another time you hve to check the value of boo wich is stored in app Context

iPhone: Cannot test InAppPurchase in sandbox after it is approved

I have a free iPhone App which uses in app purchase. I tested my first InAppPurchase with sandbox environment and it worked fine. After the InAppPurchase was approved and worked fine in App store, I added several new InAppPurchases in iTunes Connect and tried to test them in the sandbox environment. However I could not find these new InAppPurchases in my app.
The following is the code I uses to get InAppPurchase products:
//....
SKProductsRequest *prodRequest= [[SKProductsRequest alloc] initWithProductIdentifiers:
[NSSet setWithObject: prod]];
prodRequest.delegate = self;
[prodRequest start];
//....
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
int count = [response.products count];
NSLog(#"number of products:%d",count);
for (int i=0; i < count; i++) {
SKProduct* product = [response.products objectAtIndex:i];
NSLog(#"product %d:id=%# title=%# desc=%# price=%#", i, product.productIdentifier, product.localizedTitle,
product.localizedDescription,
product.price);
}
}
If I use the old InAppPurchase product id I can get it, but if I use any newly created product id I got count==0.
From what I saw, I guess may app may not be running in the sandbox environment after my first InAppPurchase was approved, but this is just a guess, because I don't know how to check if my app is in sandbox mode or not.
I searched Internet about this issue and tried the following:
1. created a new version of my app, uploaded it to iTunes connect, and rejected the binary. no use
2. deleted all my provisioning profiles and created new ones. no use
3. created an app id for my app in developer provisioning portal and created provisioning profile for that id and used it in Xcode. no use
My Xcode version was 3.2.5. I upgraded it to 4 but this did not fix the problem.
I am wondering if any one else has seen this issue and found a solution. Thanks.
OK I came across this post and got some hint:
Product Identifiers Are Valid On One Phone But Not Another
I just deleted the app from my iPod Touch, did not reboot, then tried to run my app from Xcode again, and it worked. I guess there was some states saved together with the app which determines whether to use sandbox environment for InAppPurchase or not. Although I could run my newly compiled binary without deleting the old app, I could not get rid of some old state which caused the app not running in the sandbox environment. That is what caused the problem. The solution is to delete the old app from the device before running newly compiled binary.

Facebook Connect for iOS auto signs out after quitting app

I have implemented Facebook Connect in my app, and it seems to work fine. I can publish statuses and everything. However, when I quit the app and run it again, the session token seems to have expired or something, because I can't post anymore. But if I authenticate with Facebook again, it shows that permissions have already been granted, then only when the callback to the app is called, can I post again.
What am I doing wrongly?
you should store the accessToken and expireTime of your Facebook object yourself. Restore it after startup and verify via isSessionValid, otherwise reauthorize user. You can use these functions for it:
Call the store function within your fbDidLogin, and the restore function whenever it is appropriate after startup of your app.
-(void)restoreFBAccessToken {
self.facebook.accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:#"fb_accessToken"];
self.facebook.expirationDate = [[NSUserDefaults standardUserDefaults] objectForKey:#"fb_expirationDate"];
}
-(void)storeFBAccessToken {
[[NSUserDefaults standardUserDefaults] setValue:self.facebook.accessToken forKey:#"fb_accessToken"];
[[NSUserDefaults standardUserDefaults] setValue:self.facebook.expirationDate forKey:#"fb_expirationDate"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
I'm also using FB Connect in my own app, but in an indirect way. I use it through a third-party open source kit named ShareKit. http://www.getsharekit.com/
As I remember, ShareKit does the job pretty well. It remembers those login information even though the app is shut down.
Since ShareKit is open-source, I suggest you take a look at its code. It should have an answer for you. :-)
Have you made sure to start the session once again when the app is reloaded up?