I’m having a horrible time getting this thing to work at all. I’ve spent two days reading the documentation on Salesforce’s website, the example code in the distributed SDK and just generally beating my head against the wall.
The most frustrating part is that I think I’m just missing the login screen, but I can’t find anything that will tell me how to make one. From what I can tell, it’s just a UIWebView that points to the SF login page.
Here’s what I’ve been able to figure out so far:
- Added the SDK to my project (SalesforceSDK, SalesforceOAuth, RestKit) and linked against all the libraries that are mentioned in the Git readme.
- Included
"SFRestAPI.h"in my server communications class I’m using to send and receive data from the server. -
Called the SFRestRequest using the code from the XCode template that’s distributed with the SDK:
SFRestRequest *request = [[SFRestAPI sharedInstance] requestForQuery:@"SELECT Name FROM User LIMIT 10"]; [[SFRestAPI sharedInstance] send:request delegate:self]; -
Added the delegate methods:
#pragma mark - Salesforce REST API delegate methods
- (void)request:(SFRestRequest *)request didLoadResponse:(id)jsonResponse
{
NSLog(@"%@", jsonResponse);
}
- (void)request:(SFRestRequest *)request didFailLoadWithError:(NSError*)error
{
NSLog(@"%@", error);
}
- (void)requestDidCancelLoad:(SFRestRequest *)request
{
NSLog(@"%@", request);
}
- (void)requestDidTimeout:(SFRestRequest *)request
{
NSLog(@"%@", request);
}
5. Saw this in the console:
`2012-09-11 10:23:44.128 ClientApp[39697:c07] SFRestAPI::send: <SFRestRequest 0xd4a9cb0
endpoint: /services/data
method: GET
path: /v23.0/query
queryParams: {
"q" : "SELECT Name FROM User LIMIT 10"
}`
None of the delegate methods for SFRestRequest were called.
Here’s what hasn’t worked:
Making my app delegate a subclass of SFNativeRestAppDelegate
This created about 12 duplicate symbol errors:
duplicate symbol _OBJC_CLASS_$_SFNativeRestAppDelegate in:
/Volumes/Wallace/Users/gromitt/Library/Developer/Xcode/DerivedData/ClientApp-bpccblcllzkzvudxtwutuqliagld/Build/Intermediates/ClientApp.build/Debug-iphonesimulator/ClientApp.build/Objects-normal/i386/SFNativeRestAppDelegate.o
/Volumes/Wallace/Users/gromitt/Documents/Out to Lunch/ iOS Apps/ClientApp/ClientApp/dependencies/SalesforceSDK/libSalesforceSDK.a(SFNativeRestAppDelegate.o)
duplicate symbol _OBJC_IVAR_$_SFNativeRestAppDelegate._authViewController in:
/Volumes/Wallace/Users/gromitt/Library/Developer/Xcode/DerivedData/ClientApp-bpccblcllzkzvudxtwutuqliagld/Build/Intermediates/ClientApp.build/Debug-iphonesimulator/ClientApp.build/Objects-normal/i386/SFNativeRestAppDelegate.o
/Volumes/Wallace/Users/gromitt/Documents/Out to Lunch/ iOS Apps/ClientApp/ClientApp/dependencies/SalesforceSDK/libSalesforceSDK.a(SFNativeRestAppDelegate.o)
duplicate symbol _OBJC_IVAR_$_SFNativeRestAppDelegate._viewController in:
/Volumes/Wallace/Users/gromitt/Library/Developer/Xcode/DerivedData/ClientApp-bpccblcllzkzvudxtwutuqliagld/Build/Intermediates/ClientApp.build/Debug-iphonesimulator/ClientApp.build/Objects-normal/i386/SFNativeRestAppDelegate.o
/Volumes/Wallace/Users/gromitt/Documents/Out to Lunch/ iOS Apps/ClientApp/ClientApp/dependencies/SalesforceSDK/libSalesforceSDK.a(SFNativeRestAppDelegate.o)
duplicate symbol _OBJC_IVAR_$_SFNativeRestAppDelegate._window in:
/Volumes/Wallace/Users/gromitt/Library/Developer/Xcode/DerivedData/ClientApp-bpccblcllzkzvudxtwutuqliagld/Build/Intermediates/ClientApp.build/Debug-iphonesimulator/ClientApp.build/Objects-normal/i386/SFNativeRestAppDelegate.o
/Volumes/Wallace/Users/gromitt/Documents/Out to Lunch/ iOS Apps/ClientApp/ClientApp/dependencies/SalesforceSDK/libSalesforceSDK.a(SFNativeRestAppDelegate.o)
duplicate symbol _OBJC_METACLASS_$_SFNativeRestAppDelegate in:
/Volumes/Wallace/Users/gromitt/Library/Developer/Xcode/DerivedData/ClientApp-bpccblcllzkzvudxtwutuqliagld/Build/Intermediates/ClientApp.build/Debug-iphonesimulator/ClientApp.build/Objects-normal/i386/SFNativeRestAppDelegate.o
/Volumes/Wallace/Users/gromitt/Documents/Out to Lunch/ iOS Apps/ClientApp/ClientApp/dependencies/SalesforceSDK/libSalesforceSDK.a(SFNativeRestAppDelegate.o)
duplicate symbol _kDefaultLoginHost in:
/Volumes/Wallace/Users/gromitt/Library/Developer/Xcode/DerivedData/ClientApp-bpccblcllzkzvudxtwutuqliagld/Build/Intermediates/ClientApp.build/Debug-iphonesimulator/ClientApp.build/Objects-normal/i386/SFNativeRestAppDelegate.o
/Volumes/Wallace/Users/gromitt/Documents/Out to Lunch/ iOS Apps/ClientApp/ClientApp/dependencies/SalesforceSDK/libSalesforceSDK.a(SFAccountManager.o)
ld: 6 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any help is appreciated. Thanks in advance.
So this is more than a little embarrassing, but I don’t want people to keep trying to answer this problem so here goes:
I had two copies of SFNativeAppDelegate.h added to my app. I was looking through the files included in the SF Mobile SDK, and I must have skipped over it. So I added it a second time, and that’s when my problems started.
I have it working now. Here’s what I did:
dependenciesdirectory into your existing project.SFAuthorizingViewController.xibwhile you’re in there, too. Close the Native project. You don’t need it anymore.SFDCOAuthLoginHost, and set it to either test.salesforce.com or login.salesforce.comSFNativeAppDelegate.h,SFOAuthCoordinator.handSFOAuthCredentials.hChange the interface declaration line from this:
…to this:
Add two properties to YourAppDelegate:
Go to YouAppDelegate.m. Add the following lines:
Add these methods as well (the Authorizing Coordinator was the secret sauce I was missing)
Now you’re ready to make a call using the SFRestAPI. If the user hasn’t already logged in, the SalesForce authentication page will appear the first time you try to use it.
Thanks to everyone who tried to help. Again, super-embarrassed.