How to Fetch/Create calender by O365-iOS-Connect?

2019-02-28 17:45发布

I coding a iOS app using O365-iOS-Connect to connect my app to Office 365. My app can sign in to 365 account. But i can not find some docs how to Fetch/Create calender.

O365-iOS-Connect

Thanks and sorry for my bad english.

2条回答
冷血范
2楼-- · 2019-02-28 17:53

Steps to fetch outlook calendars in iOS are:

I use MSGraph SDK & Azure AD v2.0 endpoint(for personal login)

Note: You must know how to install pods and check this link for details: https://graph.microsoft.io/en-us/

Steps:

  1. Register your iOS application on Microsoft Application Registration Portal and it will give you a client-id

  2. Install the following pods :

     pod 'MSGraphSDK-NXOAuth2Adapter'
    
     pod 'MSGraphSDK'
    
  3. Go to your ViewController and define :

    @property (strong, nonatomic) MSGraphClient *client;
    
    NSString *clientId = @"<you_clientId>"; // GLOBAL to the class
    
  4. Now import these files as:

    #import <MSGraphSDK/MSGraphSDK.h>
    
    #import <MSGraphSDK-NXOAuth2Adapter/MSGraphSDKNXOAuth2.h>
    

    5.On your button click: First you have use your client-id and define your permissions in the scope as:

    [NXOAuth2AuthenticationProvider setClientId:clientId
                                     scopes:@[@"https://graph.microsoft.com/Files.ReadWrite",
                                              @"https://graph.microsoft.com/Calendars.ReadWrite"]];
    
  5. Now you have to authenticate with your login details and Microsoft login screen automatically opens up:

    [[NXOAuth2AuthenticationProvider sharedAuthProvider] loginWithViewController:nil completion:^(NSError *error) {
    if (!error) {
        [MSGraphClient setAuthenticationProvider:[NXOAuth2AuthenticationProvider sharedAuthProvider]];
        self.client = [MSGraphClient client];
        //Authenticated successfully
    }  }];
    

If there is no error, then error is nil and it will logged in successfully.

  1. Now we can use different APIs using MSGraphClient and for calendars list:

    [[[[self.client me] calendars] request] getWithCompletion:^(MSCollection *response, MSGraphUserCalendarsCollectionRequest *nextRequest, NSError *error) {
    
           NSArray *calendars = response.value;
          // Here we are getting calendars
       }];
    
  2. Now, get calendars button action look like this:

    - (IBAction)getCalendars:(id)sender {
    
    [NXOAuth2AuthenticationProvider setClientId:clientId
                                         scopes:@[@"https://graph.microsoft.com/Files.ReadWrite",
                                               @"https://graph.microsoft.com/Calendars.ReadWrite"]];
    
    [[NXOAuth2AuthenticationProvider sharedAuthProvider] loginWithViewController:nil completion:^(NSError *error) {
    if (!error) {
        [MSGraphClient setAuthenticationProvider:[NXOAuth2AuthenticationProvider sharedAuthProvider]];
        self.client = [MSGraphClient client];
    
    
        [[[[self.client me] calendars] request] getWithCompletion:^(MSCollection *response, MSGraphUserCalendarsCollectionRequest *nextRequest, NSError *error) {
    
            NSArray *calendars = response.value;
           // Here we are getting calendars
        }];
    } }]; 
    }
    
查看更多
你好瞎i
3楼-- · 2019-02-28 18:12

we have a couple options in our GitHub code samples that might be of assistance.

One is called O365-iOS- Snippets: https://github.com/OfficeDev/O365-iOS-Snippets. The O365 iOS Snippets project shows you how to do basic operations against the Calendar, Contacts, Mail, and Files service endpoints in Office 365.

For Microsoft Graph, we've also created an iOS snippets project for that - https://github.com/OfficeDev/O365-iOS-Microsoft-Graph-Snippets. This sample shows how to use Microsoft Graph to send email, manage groups, and perform other activities with Office 365 data.

Hope this helps!

Freya H, The Office Newsroom

查看更多
登录 后发表回答