我使用 O365-iOS-Connect
编写一个 iOS 应用程序以将我的应用程序连接到 Office 365。我的应用程序可以登录 365 帐户。但是我找不到一些文档如何获取/创建日历。
谢谢,抱歉我的英语不好。
最佳答案
在 iOS 中获取 outlook 日历的步骤是:
我使用 MSGraph SDK 和 Azure AD v2.0 端点(用于个人登录)
注意:您必须知道如何安装 pod 并查看此链接了解详情:https://graph.microsoft.io/en-us/
步骤:
在 Microsoft Application Registration Portal 上注册您的 iOS 应用程序,它将为您提供一个 client-id
安装以下 pod:
pod 'MSGraphSDK-NXOAuth2Adapter' pod 'MSGraphSDK'
转到您的 ViewController 并定义:
@property (strong, nonatomic) MSGraphClient *client; NSString *clientId = @"<you_clientId>"; // GLOBAL to the class
现在将这些文件导入为:
#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"]];
现在您必须使用您的登录详细信息进行身份验证,Microsoft 登录屏幕会自动打开:
[[NXOAuth2AuthenticationProvider sharedAuthProvider] loginWithViewController:nil completion:^(NSError *error) { if (!error) { [MSGraphClient setAuthenticationProvider:[NXOAuth2AuthenticationProvider sharedAuthProvider]]; self.client = [MSGraphClient client]; //Authenticated successfully } }];
如果没有报错,则error为nil,登录成功。
现在我们可以通过 MSGraphClient 和日历列表来使用不同的 API:
[[[[self.client me] calendars] request] getWithCompletion:^(MSCollection *response, MSGraphUserCalendarsCollectionRequest *nextRequest, NSError *error) { NSArray *calendars = response.value; // Here we are getting calendars }];
现在,获取日历按钮操作如下所示:
- (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/