3

I am tring to open appstore page as model view inside application using following code

[NSDictionary dictionaryWithObject:@"APPID" forKey:SKStoreProductParameterITunesItemIdentifier];

SKStoreProductViewController *productViewController = [[SKStoreProductViewController alloc] init];
[self presentViewController:productViewController animated:YES completion:nil];

but when appstore is open inside application, it is opening as blank page. Please refer screenshoot attachedBlank appstore page when opened as model view

I dont understand why appstore page of my app is not opening. I am passing APPID in above code.

Is there any other way to rate application without closing app ?

Vidhi
  • 2,026
  • 2
  • 20
  • 31
  • how do you pass the `ID` to the controller? how do you set the `delegate` class here? many-many opened question are still here... – holex May 28 '14 at 12:59
  • first off is the app live ? and second it will not always work on the simulator. – rckoenes May 28 '14 at 12:59
  • @rckoenes : Yes app is live and i tried in simulator as well as ios 6.1 device , ios 7 device. – Vidhi May 28 '14 at 13:08
  • @holex : actually i get this code from http://stackoverflow.com/questions/19585037/rate-and-review-within-an-app-possible-in-ios7 question and that answer is approved so i thought it might work. Should i change anything in code? How can i pass that directory which contains APPID to SKStoreProductViewController ? – Vidhi May 28 '14 at 13:10
  • @user2207961, that answer does not hold the entire implementation, you cannot just copy and paste a tiny code-fragment, it won't work at all. – holex May 28 '14 at 13:35

2 Answers2

1

basically, something like this could help on you, after you linked the StoreKit.framework to your project. please note, it may not be working on simulator; on real device it works well.

.h

@interface UIYourViewController : UIViewController <SKStoreProductViewControllerDelegate> { }

.m

- (void)myOwnCustomMethod {

    SKStoreProductViewController *_controller = [[SKStoreProductViewController alloc] init];
    [_controller setDelegate:self];
    [_controller loadProductWithParameters:[NSDictionary dictionaryWithObjectsAndKeys:@"364709193", SKStoreProductParameterITunesItemIdentifier, nil] completionBlock:^(BOOL result, NSError *error) {
        if (result) {
            [self.navigationController presentViewController:_controller animated:TRUE completion:nil];
        } else {
            // you can handle the error here, if you'd like to.
        }
    }];

}

#pragma mark - <SKStoreProductViewControllerDelegate>

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
    [self dismissViewControllerAnimated:TRUE completion:nil];
}
holex
  • 23,961
  • 7
  • 62
  • 76
0

In Swift 3,

import StoreKit
class DetailViewController: UIViewController {

    @IBAction func onEditButton(_ sender: UIBarButtonItem) {
        let vc = SKStoreProductViewController()
        vc.delegate = self
        present(vc, animated: true, completion: nil)
        vc.loadProduct(withParameters: [SKStoreProductParameterITunesItemIdentifier: 351091731]) { (success, error) in
            if !success {
                print("\(error)")
            }
        }
    }
}

extension DetailViewController: SKStoreProductViewControllerDelegate {
    func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
        viewController.dismiss(animated: true, completion: nil)
    }
}

Make sure SKStoreProductParameterITunesItemIdentifier's value is Number, as stated in its head file, though String value is currently OK.

DawnSong
  • 4,752
  • 2
  • 38
  • 38