snaggs
snaggs

Reputation: 5713

How to check if iOS application uses 'StoreKit.framework'?

I write SDK for iOS and I want to validate if StoreKit.framework is linked to application that uses my SDK, so I run:

if ([SKStoreProductViewController class]) {
        SKStoreProductViewController *storeController =
                        [[ SKStoreProductViewController alloc ] init ];
        // ...
    }

enter image description here

However even if StoreKit.framework is not linked [SKStoreProductViewController class still returns true.

How to solve this problem?


Edit 1

as @x4h1d pointed I created new empty project and added to default Controller:

BOOL isStoreKitAvailable = 
   (NSClassFromString(@"SKStoreProductViewController") != nil);

// => YES (there is no linked frameworks at all, why I get YES?)

Edit 2

My Provisioning profile has In-App Purchase enabled (not a project itself)

from iOS App IDs:

enter image description here

However from Xcode:

enter image description here

Maybe this is a reason why even empty application has build-in StoreKit?

Upvotes: 14

Views: 3217

Answers (4)

Hitesh Surani
Hitesh Surani

Reputation: 13537

//SWIFT 
class func allFrameworks() -> [AnyObject]

//OBJECTIVE-C
+ (NSArray *)allFrameworks

From NSBundle

+allFrameworks
Returns an array of all of the application’s bundles that represent frameworks.

Return Value

An array of all of the application’s bundles that represent frameworks. Only frameworks with one or more Objective-C classes in them are included.

Import Statement

import Foundation

Availability

Available in iOS 2.0 and later.

How to Use

(NSBundle.allFrameworks() -> Return Array of All framework use in project.

You can Check Using for loop apllication contain storeKit.framework or Not as Below.

Swift :---

func isStoreKitAvailable() -> Bool {
    for frameWorkName in Bundle.allFrameworks {
        if ((frameWorkName.classNamed("SKStoreProductViewController")) != nil) {
            return true;
        }
    }
    return false;
}

Objective C :---

- (BOOL)isStoreKitAvailable {

    for (NSBundle *frameWorkName in NSBundle.allFrameworks) {
        if ([frameWorkName classNamed:@"SKStoreProductViewController"]) {
            return YES;
        }
    }
    return NO;
}

Find more reference from here

Upvotes: 0

Hassan Aftab
Hassan Aftab

Reputation: 644

You can check the storekit availibility using following code.

func checkStoreKitAvailibility() -> Bool {
    for bundle in Bundle.allFrameworks {
        if ((bundle.classNamed("SKStoreProductViewController")) != nil) {
            return true;
        }
    }
    return false;
}

Edit: For Objective-C you can use:

- (BOOL)checkStoreKitAvailibility {

    for (NSBundle *bundle in NSBundle.allFrameworks) {
        if ([bundle classNamed:@"SKStoreProductViewController"]) {
            return YES;
        }
    }
    return NO;
}

Upvotes: 2

Mithun kumar
Mithun kumar

Reputation: 662

In Xcode,

when we enable the In-App purchase under Capabilities, Xcode automatically links StoreKit.framework and Add the In-App purchase feature to our App ID. Similarly if our App ID already have In-App purchase enabled the same happens.

So by doing simply,

BOOL isStoreKitAvailable = (NSClassFromString(@"SKStoreProductViewController") != nil);

I hope this might help you.

Upvotes: 0

Sachin Vas
Sachin Vas

Reputation: 1767

In the Linked Frameworks and Libraries make it Optional instead of Required. So, that if the application developers wants it to implement he will mark the framework as Required in the application. Now if you use the [SKStoreProductViewController class]. it may crash use the NSStringFromClass(@"SKStoreProductViewController") to determine if its safe to use it.

Upvotes: 0

Related Questions