Bug Hunter Zoro
Bug Hunter Zoro

Reputation: 1915

Office 365 iOS: Not able to fetch List Items from Office 365 SDK

I have added the announcement app and added few items to it, now i want to fetch the items from my announcement list so I have used the below code

token_Obtained_During_first_time_Login: This is the token that i get when i login for the first time using the acquireTokenWithResource method of ADAuthenticationContext class

- (void)getClientList {

NSString *appToken = [[NSUserDefaults standardUserDefaults]
 valueForKey:@"token_Obtained_During_first_time_Login"];
NSString* hostName = @"https://myTenant.sharepoint.com/sites/myApp";


OAuthentication *credentials = [[OAuthentication alloc] initWith:appToken];
ListClient *client = [[ListClient alloc]
                  initWithUrl:hostName
                  credentials:credentials];

NSURLSessionTask* task =  [client getListItems:@"MyAnnouncements" 
callback:^(NSMutableArray *listItems, NSError *error)  {
    if (error==nil) {
    NSLog(@"%@",listItems);
    }
}];

[task resume];

}

I have even debugged the 365 code and it provides me the below URL for getListItems: callback method

https://myTenant.sharepoint.com/sites/myApp/_api/lists/GetByTitle('MyAnnouncements')/Items

I have even tried the same using getTokenWith method which comes with the sample code

- (void)getAnnouncementList:(void (^)(ListClient *))callback{
NSString* hostName = @"https://myTenant.sharepoint.com";

[self getTokenWith:hostName :true completionHandler:^(NSString *token) {
OAuthentication *credentials = [[OAuthentication alloc] initWith:token];

callback([[ListClient alloc]initWithUrl:hostName credentials:credentials]);
 }];
}

But still no luck i get the list as nil

Please guide on how this can be resolved, I have even verified the rights in the Azure Directory everything seems fine am able to fetch data of one drive, mails and calendar but list is a place where i am stuck.

Every time i call the above code i get the response nil not sure what am passing wrong, my guess is the token.

Upvotes: 0

Views: 181

Answers (1)

Bug Hunter Zoro
Bug Hunter Zoro

Reputation: 1915

I resolved this issue by making a change in the apiUrl present in the ListClient.m file of Office 365.

All i did was changed it to

const NSString *apiUrl = @"/sites/mobileApp/_api/web/Lists";

Making the above change did the trick and now i can access all the list data.

Upvotes: 1

Related Questions