saturngod / IAPHelper

No more maintenance for this repo. Please use the https://github.com/bizz84/SwiftyStoreKit
MIT License
1.56k stars 280 forks source link

Use of undeclared identifier productIdentifier #4

Closed niravspaceo closed 10 years ago

niravspaceo commented 10 years ago

Hello,

I have used your code to make in-app and i am getting an error here, [[IAPShare sharedHelper].iap provideContent:productIdentifier]; . it is saying me that use of undeclared identifier productIdentifier . how to solve it??

Thanks.

saturngod commented 10 years ago

productIdentifier should be NSString.

Example :

NSString productIdentifier = @"com.comquas.nsmag.issue1";
[[IAPShare sharedHelper].iap provideContent:productIdentifier];

or

NSString productIdentifier = transaction.payment.productIdentifier;
[[IAPShare sharedHelper].iap provideContent:productIdentifier];

Sorry for my example is not clear.

niravspaceo commented 10 years ago

Hello,

Thanks a lot..!!! It worked.....

I am facing another problem and that is how to restore particular in-app purchase.? Can you just give me some lines of code so i can integrate it.

Thanks,

saturngod commented 10 years ago

You can restore like following code

[[IAPShare sharedHelper].iap restoreProductsWithCompletion:^(SKPaymentQueue *payment, NSError *error) {

NSLog(@"Transactions %@",payment.transactions);

}];
niravspaceo commented 10 years ago

but how can i come to know whether restore has done successfully or it fails?

and another problem i am facing is , when i purchase product successfully ,after that i stop debugging in device, and again i debug in device and when i check whether that product has purchased or not, at that time it gave me not purchased , though i have purchased it before and it goes to again for purchase.

What can be the problem?

saturngod commented 10 years ago

Next time open the app , you can check with isPurchasedProductsIdentifier function.

if([[IAPShare sharedHelper].iap isPurchasedProductsIdentifier:@"com.comquas.iap.test"]
{
    // require saving product identifier first
}   

if you want to get all purchased product , you can get with

NSLog(@"%@",[IAPShare sharedHelper].iap.purchasedProducts);

For restore success or not , you can check the error is nil or not

[[IAPShare sharedHelper].iap restoreProductsWithCompletion:^(SKPaymentQueue *payment, NSError *error) {
if(error==nil)
{
NSLog(@"restore success");
}
}];

please read the Read Me file for detail.

niravspaceo commented 10 years ago

Thanks a lot man.. It was my problem.. I didn't allocated [IAPShare sharedHelper].iap that's why next time open the app it redirects me to purchase data every time.

Thanks,

saturngod commented 10 years ago

:+1: