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

标签 ios outlook calendar ms-office office365

我使用 O365-iOS-Connect 编写一个 iOS 应用程序以将我的应用程序连接到 Office 365。我的应用程序可以登录 365 帐户。但是我找不到一些文档如何获取/创建日历。

O365-iOS-Connect

谢谢,抱歉我的英语不好。

最佳答案

在 iOS 中获取 outlook 日历的步骤是:

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

注意:您必须知道如何安装 pod 并查看此链接了解详情:https://graph.microsoft.io/en-us/

步骤:

  1. 在 Microsoft Application Registration Portal 上注册您的 iOS 应用程序,它将为您提供一个 client-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.点击您的按钮:首先,您使用您的客户端 ID 并将您在范围内的权限定义为:

    [NXOAuth2AuthenticationProvider setClientId:clientId
                                     scopes:@[@"https://graph.microsoft.com/Files.ReadWrite",
                                              @"https://graph.microsoft.com/Calendars.ReadWrite"]];
    
  5. 现在您必须使用您的登录详细信息进行身份验证,Microsoft 登录屏幕会自动打开:

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

如果没有报错,则error为nil,登录成功。

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

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

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

关于ios - 如何通过 O365-iOS-Connect 获取/创建日历?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35191962/

相关文章:

表格之间的 HTML 电子邮件空间(Gmail 和 Outlook)

Python:使用日历将日期编号转换为日期名称

Android 日历 "dtStart"返回未知值

html - Microsoft Outlook 电子邮件边框覆盖 CSS

rest - 当我们检查接收时间更长时,带有 $search 过滤器的 Microsoft Graph Mail API 不起作用

calendar - .ics 文件中的单日全天约会

ios - 自动布局违反平移旋转动画

ios - 在 UITableViewCell 中扩展 UITextView

ios - 执行后台提取后通知用户

ios - 尝试重新排序 NSMutableArray 时出现运行时异常