如何通过 O365-iOS-Connect 获取/创建日历? [英] How to Fetch/Create calender by O365-iOS-Connect?
问题描述
我使用 O365-iOS-Connect
编写 iOS 应用程序以将我的应用程序连接到 Office 365.我的应用程序可以登录到 365 帐户.但我找不到一些文档如何获取/创建日历.
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.
感谢和抱歉我的英语不好.
Thanks and sorry for my bad english.
推荐答案
在 iOS 中获取 Outlook 日历的步骤是:
Steps to fetch outlook calendars in iOS are:
我使用 MSGraph SDK &Azure AD v2.0 端点(用于个人登录)
I use MSGraph SDK & Azure AD v2.0 endpoint(for personal login)
注意:您必须知道如何安装 pod 并查看此链接了解详细信息:https://graph.microsoft.io/en-us/
Note: You must know how to install pods and check this link for details: https://graph.microsoft.io/en-us/
步骤:
在 Microsoft 应用程序注册门户上注册您的 iOS 应用程序,它将为您提供一个客户端 ID
Register your iOS application on Microsoft Application Registration Portal and it will give you a client-id
安装以下 pod:
pod 'MSGraphSDK-NXOAuth2Adapter'
pod 'MSGraphSDK'
转到您的 ViewController 并定义:
Go to your ViewController and define :
@property (strong, nonatomic) MSGraphClient *client;
NSString *clientId = @"<you_clientId>"; // GLOBAL to the class
现在将这些文件导入为:
Now import these files as:
#import <MSGraphSDK/MSGraphSDK.h>
#import <MSGraphSDK-NXOAuth2Adapter/MSGraphSDKNXOAuth2.h>
5.在您的按钮上单击:首先您使用您的客户端 ID 并将您在范围内的权限定义为:
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"]];
现在您必须使用您的登录详细信息进行身份验证,Microsoft 登录屏幕会自动打开:
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
} }];
如果没有错误,则error为nil,登录成功.
If there is no error, then error is nil and it will logged in successfully.
现在我们可以通过 MSGraphClient 和 for calendars list 使用不同的 API:
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
}];
现在,让日历按钮操作如下所示:
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
}];
} }];
}
这篇关于如何通过 O365-iOS-Connect 获取/创建日历?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!