如何通过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 Application上注册您的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
} }];
如果没有错误,则错误是nil并且它将成功登录。
If there is no error, then error is nil and it will logged in successfully.
-
现在我们可以使用 MSGraphClient <使用不同的API / strong>和用于日历列表:
[[[[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屋!