3
votes

I came to know that we could use REST apis to get data from SharePoint sites. Also SharePoint supports REST from 2010 onwards. I got the API for listing the data and its details from SharePoint. It is "ListData.svc". Is there any other APIs similar to that using which we could authenticate our site. I tried it browser(listdata.svc) and before that I was logged in. If I am logged out and do the "siteUrl/_vti_bin/ListData.svc", I am not able to get the result, request getting timed out or sometimes it shows Webpage is not available. If anyone know how to SharePoint stuffs in iPhone application, please share something on the same.

3

3 Answers

2
votes

Read this: http://sharepointsemantics.com/2011/07/the-client-side-object-model-help-with-headless-authentication-in-sharepoint-online/ Make sure you read the linked articles written by Chris Johnson, following the information there should solve your authentication woes.

Sidenote, you pretty much HAVE to use forms authentication on the SharePoint end.

2
votes

Here is the way I have done this for NTLM authentication to SharePoint 2010 over http. It works and returns JSON dictionary from any call to the listdata.svc (e.g. call to URL yourdomain/_vti_bin/listdata.svc/YourList):

Grab AFNetworking and follow the instructions to get it into your XCode application.

When you have AFNetworking compiling in your project you need to subclass AFHTTPClient class of AFNetworking framework. E.g. add a new class to your iOS XCode project and choose AFHTTPClient as it's object type.

Once you have subclassed you get something like the following:

YourHTTPClient.h

#import "AFHTTPClient.h"
#import "AFJSONRequestOperation.h"
#import "AFNetworkActivityIndicatorManager.h"

typedef void(^OLClientSuccess) (AFJSONRequestOperation *operation, id responseObject);
typedef void(^OLClientFailure) (AFJSONRequestOperation *operation, NSError *error);

@interface OLHTTPClient : AFHTTPClient
{

NSString *strBASEURL;
NSString *strUser;
NSString *strPassword;

}

@property (nonatomic, retain) NSString *strUser;
@property (nonatomic, retain) NSString *strPassword;
@property (nonatomic, retain) NSString *strBASEURL;

+(id) sharedClient;

- (void)setUsername:(NSString *)username andPassword:(NSString *)password;

-(void) getStuff:(OLClientSuccess) success failure:(OLClientFailure) failure;

@end

The in your YourHTTPClient.m file you could have the code below but in this .m file is where you will implement your custom method calls to get your list data from SharePoint. See below:

Code fragment for authentication from YourHTTPClient.m:

- (void)getPath:(NSString *)path parameters:(NSDictionary *)parameters
    success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
    failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
{
NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:parameters];
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure];
[operation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
    NSURLCredential *newCredential = [NSURLCredential credentialWithUser:self.User password:self.password persistence:NSURLCredentialPersistenceForSession];
    [challenge.sender useCredential:newCredential forAuthenticationChallenge:challenge];
}];
[self enqueueHTTPRequestOperation:operation];
}

@end

I have only tried the above with a SharePoint 2010 environment configured to authenticate using NTLM. It may need reconfiguration if you need to authenticate using Kerberos but I suspect it is possible also using AFNetworking.

0
votes

Look at this project, it supports SharePoint 2013 RestAPI.Its working for me, and very sure it will work for you also.

https://github.com/jimmywim/SPRestAPI

By default the SPRESTQuery provides the response in XMl, If you want response in json you will have to write this line in executeQuery Method.

[apiRequest setValue:@"application/json;odata=verbose" forHTTPHeaderField:@"Accept"];