如何通过O365-iOS-Connect获取/创build日历?

我使用O365-iOS-Connect编码iOS应用程序,将我的应用程序连接到Office 365.我的应用程序可以login到365帐户。 但我找不到一些文件如何取/创build日历。

O365-IOS-连接

谢谢你,对不起我的英文不好。

在iOS中获取Outlook日历的步骤如下:

我使用MSGraph SDKAzure AD v2.0端点 (用于个人login)

注意 :您必须知道如何安装pod并查看此链接以获取详细信息: https : //graph.microsoft.io/en-us/

脚步:

  1. 注册您的iOS应用程序在Microsoft应用程序注册门户,它会给你一个客户端ID

  2. 安装以下Pod:

      pod 'MSGraphSDK-NXOAuth2Adapter' pod 'MSGraphSDK' 
  3. 转到您的ViewController并定义:

     @property (strong, nonatomic) MSGraphClient *client; NSString *clientId = @"<you_clientId>"; // GLOBAL to the class 
  4. 现在将这些文件导入为:

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

    5.在你的button上点击:首先你要使用你的客户端ID,并在范围内定义你的权限:

     [NXOAuth2AuthenticationProvider setClientId:clientId scopes:@[@"https://graph.microsoft.com/Files.ReadWrite", @"https://graph.microsoft.com/Calendars.ReadWrite"]]; 
  5. 现在您必须使用您的login信息进行身份validation,并且Microsoftlogin屏幕会自动打开:

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

如果没有错误,那么错误是零,它将成功login。

  1. 现在我们可以使用不同的API使用MSGraphClient日历列表

     [[[[self.client me] calendars] request] getWithCompletion:^(MSCollection *response, MSGraphUserCalendarsCollectionRequest *nextRequest, NSError *error) { NSArray *calendars = response.value; // Here we are getting calendars }]; 
  2. 现在,获取日历button操作如下所示:

     - (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 }]; } }]; } 

我们在我们的GitHub代码示例中有几个选项可能会有所帮助。

一个叫做O365-iOS-Snippets: https : //github.com/OfficeDev/O365-iOS-Snippets 。 O365 iOS Snippets项目向您展示了如何针对Office 365中的日历,联系人,邮件和文件服务terminal进行基本操作。

对于Microsoft Graph,我们还为此创build了一个iOS片段项目 – https://github.com/OfficeDev/O365-iOS-Microsoft-Graph-Snippets 。 本示例演示如何使用Microsoft Graph发送电子邮件,pipe理组以及使用Office 365数据执行其他活动。

希望这可以帮助!

Freya H,办公室新闻室