Search code examples
iospinterest

How do I Integrate my Swift IOS app with Pinterest?


I'm trying to integrate pinterest into my IOS app with swift. I've got an image and click a button to have it post to my Pinterest account. I've gone through the Pinterest SDK documents: https://developers.pinterest.com/docs/sdks/ios/? I've gotten the Podfile installed and I've got an app id, but I'm stuck at step 4. 4. Configure the PDK Client Finally, you’ll need to link your App ID to the PDK Client in your app. [PDKClient configureSharedInstanceWithAppId:@"12345"];

I'm not quite sure what exactly they mean by this. Which file do I add this line to and where in that file do I add it?

I checked some of the posts here, but they all seem VERY old, so I wasn't sure they were correct.


Solution

  • The file is the AppDelegate and the method where you need to put your code is:

    application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)

    Objective-C:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [PDKClient configureSharedInstanceWithAppId:@"YourAppId"]
        .
        .
        .
        return YES;
    }
    

    Swift:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        PDKClient.configureSharedInstanceWithAppId("YourAppId")
        .
        .
        .
        return true
    }
    

    P.S. Don't forget to import PinterestSDK in the appDelegate