Thursday, 19.10.2017, 05:48
| RSS

Engineer M DevelopmentMA

Главная » 2012 » July » 31 » SharePoint on iOS
SharePoint on iOS
12:20

How to access SharePoint server from iOS?
For connect and receive data from the web service SharePoiint you can use the ASIHTTPRequest library. Download source code and read documentation here.

The first step is connecting to website on the SharePoiint server. Example URL: https://sp.company.com/mobile/Shared%20Document/Forms/AllItems.aspx . This URL has five parts:
https:// - the URL protocol;
sp.company.com/ - the server name;
mobile/ - the website;
Shared%20Document/ - the item stored on website "mobile";
Forms/AllItems.aspx - the helpers for browsers.

On the website https://sp.company.com/mobile/ exists user "visitor" with password "123123" and an authentication uses the NTLM scheme. Via ASIHTTPRequest you have to connect to SharePoint, it's doing next code:

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:@"https://sp.company.com/mobile/"];     
[request setUsername:@"visitor"];     
[request setPassword:@"123123"];     
[request setDelegate:self];     
[request startAsynchronous];

If you want to receive username and password from user via Login Form, then you can use delegate methods:
1) Results of request:
- (IBAction)topSecretFetchFailed:(ASIHTTPRequest *)theRequest 
 [textView setText:[[request error] localizedDescription]]; 
 [textView setFont:[UIFont boldSystemFontOfSize:12]]; 

- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)theRequest 
 [textView setText:[request responseString]]; 
 [textView setFont:[UIFont boldSystemFontOfSize:12]]; 
}  

2) Authentication Login Form: 
- (void)authenticationNeededForRequest:(ASIHTTPRequest *)theRequest 
 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Please Login" message:[request authenticationRealm] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil] autorelease];
 [alertView addTextFieldWithValue:@"" label:@"Username"];
 [alertView addTextFieldWithValue:@"" label:@"Password"];
 [alertView show]; 
 
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
 if (buttonIndex == 1) 
 { 
   if ([[self request] authenticationNeeded] == ASIHTTPAuthenticationNeeded) 
   { 
     [[self request] setUsername:[[alertView textFieldAtIndex:0] text]];
     [[self request] setPassword:[[alertView textFieldAtIndex:1] text]];
     [[self request] retryUsingSuppliedCredentials]; 
   } 
   else if ([[self request] authenticationNeeded] == ASIProxyAuthenticationNeeded) 
   { 
     [[self request] setProxyUsername:[[alertView textFieldAtIndex:0] text]]; 
     [[self request] setProxyPassword:[[alertView textFieldAtIndex:1] text]]; 
     [[self request] retryUsingSuppliedCredentials]; 
   } 
 } 
 else 
 { 
   [[self request] cancelAuthentication]; 
 } 
}

After successfully access, you can request all List of website. The request making with protocol SOAP. To see examples code of SOAP on your website, you have to visit next directory: "/_vti_bin/Lists.asmx" -> https://sp.company.com/mobile/_vti_bin/Lists.asmx . It's shows you all methods of List Web Service. Now need the method GetListCollection. The request looks like:

 NSString *soapMessage = [NSString stringWithString:@"\n"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n"
"<soap12:Body>\n"
"<GetListCollection xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\" />\n"
"</soap12:Body>\n"
"</soap12:Envelope>\n"
];

This message have to be encoded and set in post data of Requester 
(it's code for SOAP version 2):

NSURL *url = [NSURL URLWithString:
@"https://sp.company.com/mobile/_vti_bin/Lists.asmx"];   
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];     
[request setUsername:@"visitor"];     
[request setPassword:@"123123"];     
[request setDelegate:self];     
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[request addRequestHeader:@"Content-Type" value:@"application/soap+xml; charset=utf-8"];     
[request addRequestHeader:@"Content-Length" value:msgLength];     
[request setRequestMethod:@"POST"];    
[request appendPostData:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];     
[request startAsynchronous];

You will receive SOAP answer with Lists from website "mobile" and information about it. From example, it's will be the "Shared Document" List. The information contains more data: Title, Descriptions, Name, Id, urls, dates, type and etc. If you want to get all Items of List then you need attributes 'Id' or 'Name', example: Name="{88299283-69DC-45B2-B4BF-4E5413ED4E50}".
The name you have to use in request at method GetList. Example SOAP:

NSString *listName = [NSString stringWithUTF8String:"88299283-69DC-45B2-B4BF-4E5413ED4E50"];//Shared%20Documents
    
NSString *soapMessage = [NSString stringWithFormat:@"\n"
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">\n"
"<soap12:Body>\n"
"<GetList xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">\n"
"<listName>{%@}</listName>\n"
"</GetList>\n"
"</soap12:Body>\n"
"</soap12:Envelope>\n"
, listName];

This string you can set in the previous code. The answer will contain information of Items, it will be files or directories that was shared on the "mobile" website.

Категория: Lessons | Просмотров: 3820 | Добавил: admin | Рейтинг: 5.0/1 |
Всего комментариев: 0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]
Меню сайта
Разделы новостей
Concept Software [2]
Programs are planned or under construction.
Software [10]
Release Software
Lessons [12]
About Me [1]
Infa about yourself, documents, certificates ...
Documentation [4]
Documentation of projects
Календарь новостей
«  July 2012  »
SuMoTuWeThFrSa
1234567
891011121314
15161718192021
22232425262728
293031
Поиск
Друзья сайта
Статистика
Copyright Macarov Anatoli © 2017
Free website builderuCoz