Search code examples
iosobjective-cswiftstorekitios-animations

Present SKStoreProductViewController with no animation


I am trying to present an instance of SKStoreProductViewController without the animation.

Snippets of the code from the view controller StoreKit is presenting from:

Objective-C

SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc] init];
[storeProductVC loadProductWithParameters: <PARAMETERS> completionBlock: nil];

[self presentViewController: storeProductVC animated: NO completion: nil];

Swift

let storeProductVC = SKStoreProductViewController()
storeProductVC.loadProduct(withParameters: <PARAMETERS>, completionBlock: nil)

self.present(storeProductVC, animated: false, completion: nil)

Passing in NO for the animated flag did not work. The StoreKit view controller still presented with animation. I know the theme of Apple frameworks is to allow minimal customizations, but I am hoping this isn't the case.


Solution

  • You can present it without animation in a separate UIWindow.

    Objective-C

    SKStoreProductViewController *storeProductVC = [[SKStoreProductViewController alloc] init];
    [storeProductVC loadProductWithParameters: <PARAMETERS> completionBlock: nil];
    
    UIScreen *mainScreen = [UIScreen mainScreen];
    
    // Note: storeKitWindow should be strongly held, i.e. a property
    self.storeKitWindow = [[UIWindow alloc] initWithFrame: mainScreen.bounds];
    self.storeKitWindow.screen = mainScreen;
    self.storeKitWindow.windowLevel = UIWindowLevelStatusBar;
    self.storeKitWindow.rootViewController = storeProductVC;
    
    [self.storeKitWindow makeKeyAndVisible];
    

    Swift

    let storeProductVC = SKStoreProductViewController()
    storeProductVC.loadProduct(withParameters: [:], completionBlock: nil)
    
    let mainScreen = UIScreen.main
    
    // Note: storeKitWindow should be strongly held, i.e. a property
    storeKitWindow = UIWindow(frame: mainScreen.bounds)
    storeKitWindow.screen = mainScreen
    storeKitWindow.windowLevel = UIWindowLevelStatusBar
    storeKitWindow.rootViewController = storeProductVC
    
    storeKitWindow.makeKeyAndVisible()