0

All the documentation I see always talks about using the forceios command to create a new application using the salesforce SDK. I have an existing native iOS application and I want to easily add the salesforce SDK. Unfortunately there doesn't seem to be any cocoapods support, so what's the recommended approach?

3 Answers 3

6

Update April, 2015

Cocoapods is now supported

  • If you don’t already have a Podfile for your project, create one in the project’s root directory. A Podfile is simply a text file named Podfile.
  • Open your Podfile in a text editor and add a pod command that references a Mobile SDK podspec. For example, to add all modules to your app, use the following pod command: pod ‘SalesforceMobileSDK-iOS’
  • Open a Terminal window and run pod install from your project directory.

Original Answer

I was looking at doing this recently, but it was for a new app so I ended up just using the create and then reshuffling things to move the login to a different stage in the life cycle etc.

Now I've had some experience with it though, what I'd do is this:

1: Create a project using the forceios tool

2: Copy from that project everything in the Dependencies folder to the existing project (ignore iMag, that's something bespoke to this project).

Dependencies

3: Copy the SalesforceSDKResources bundle, and then merge in the required parts of the Settings bundle. If this isn't customised for your app you can probably just overwrite it.

Bundles

4: Compare the existing project with the forceios project to see if there's any frameworks you'll need to add.

5: After that you should be in a position to use the SDK. I created a single SalesforceManager class in my project that handles all of the interaction with the SDK:

@interface SalesforceManager : NSObject <SFAuthenticationManagerDelegate, SFUserAccountManagerDelegate, SFRestDelegate>

For reference, the way I handle initialisation and login is below. Once it's authenticated etc. you'll be able to use it as per the docs, using [SFRestAPI sharedInstance], personally I've found the blocks way of doing things to be far easier to handle than dealing with delegates.

If you get any build errors there's a chance you'll need to add some library search paths etc..

- (id)init
{
    self = [super init];

    if(self)
    {
        [SFLogger setLogLevel:SFLogLevelDebug];

        // These SFAccountManager settings are the minimum required to identify the Connected App.
        [SFUserAccountManager sharedInstance].oauthClientId = RemoteAccessConsumerKey;
        [SFUserAccountManager sharedInstance].oauthCompletionUrl = OAuthRedirectURI;
        [SFUserAccountManager sharedInstance].scopes = [NSSet setWithObjects:@"web", @"api", nil];

        // Auth manager delegate, for receiving logout and login host change events.
        [[SFAuthenticationManager sharedManager] addDelegate:self];
        [[SFUserAccountManager sharedInstance] addDelegate:self];
    }

    return self;
}

- (void)attemptLoginOnSuccess:(SFManagerLoginSuccessBlock)successBlock
                onFailure:(SFManagerLoginFailBlock)failureBlock
{
    __weak SalesforceManager *weakSelf = self;

    self.initialLoginSuccessBlock = ^(SFOAuthInfo *info)
    {
        weakSelf.authenticated = TRUE;
        successBlock();

    };

    self.initialLoginFailureBlock = ^(SFOAuthInfo *info, NSError *error)
    {
        [[SFAuthenticationManager sharedManager] logout];
        weakSelf.authenticated = FALSE;
        failureBlock();
    };

    [[SFAuthenticationManager sharedManager] loginWithCompletion:self.initialLoginSuccessBlock failure:self.initialLoginFailureBlock];
}
2
  • Thanks for the answer. I was afraid that would be the answer :) It's disappointing to see that cocoapods is not supported. I wonder if anyone has had success embedding it as a subproject?
    – jeffbailey
    Commented Sep 18, 2014 at 13:33
  • 1
    @jeffbailey, incase you hadn't already discovered this. Cocoapods is now supported. See my answer below. Hope that helps.
    – johnrechd
    Commented Apr 28, 2015 at 23:31
2

If you are integrating into an existing app, you could certainly run the forceios command to get the files, then copy them over. But why not just clone from the git repository?

https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Distribution

You can even add it as a submodule to your project (don't forget to init their submodules as well), then you can have versioned instances of your app in git with their corresponding version of SF SDK as well. That seems like the proper solution to me.

FYI, you will still need to do the other set up items as mentioned in the above answer.

They have decent instructions on how to do this on the github page linked above. After going through this yesterday, this is the intended method for integrating into an existing app.

Happy programming :)

UPDATE: Just FYI, salesforce SDK is now managed as a cocoa pod as well. I updated my application to use the cocoa pod instead of the submodule method. You can simply set it up in your Podfile like this.

pod 'SalesforceMobileSDK-iOS', '~> 3.1.0'

Nicest way to manage so far :)

1

I reached out to the Salesforce mobile team about this. They were very responsive and pointed me to the following:

https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Distribution

They also updated it to make it current. This is the best approach until they support cocoapods in the future.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .