Important
This preview SDK has been deprecated and this repo is no longer being maintained. We recommend that you use Microsoft Graph and the associated Microsoft Graph SDKs instead.
Note
Security vulnerabilities may exist in the project, or its dependencies. If you plan to reuse or run any code from this repo, be sure to perform appropriate security checks on the code or dependencies first. Do not use this project as the starting point of a production Office Add-in. Always start your production code by using the Office/SharePoint development workload in Visual Studio, or the Yeoman generator for Office Add-ins, and follow security best practices as you develop the add-in.
Easily integrate services and data from Discovery into native iOS apps using this Objective-C library.
Information about official Microsoft support is available here.
This library is generated from the Discovery API metadata using Vipr and Vipr-T4TemplateWriter and uses a shared client stack.
To use this library in your project, follow these general steps, as described further below:
- Configure a Podfile.
- Set up authentication.
- Construct an API client.
-
Create a new Xcode application project from the Xcode splash screen. In the dialog, choose iOS > Single View Application. Name your application as you wish; we'll assume the name DiscoveryQuickStart here.
-
Add a file to the project. Choose iOS > Other > Empty from the dialog and name your file
Podfile
. -
Add these lines to the Podfile to import the Discovery SDK
source 'https://github.com/CocoaPods/Specs.git'
xcodeproj 'DiscoveryQuickStart'
pod 'MSOffice365-Discovery-SDK-iOS'
NOTE: For detailed information on Cocoapods and best practices for Podfiles, read the Using Cocoapods guide.
-
Close the Xcode project.
-
From the command line, change to your project's directory. Then run
pod install
.
NOTE: Install Cocoapods first of course. Instructions here.
- From the same location in the terminal, execute
open DiscoveryQuickStart.xcworkspace
to open a workspace containing your original project together with imported pods in Xcode.
With your project prepared, the next step is to initialize the dependency manager and an API client.
❗ If you haven't yet registered your app in Azure AD, you'll need to do so before completing this step by following these instructions.
- Right-click the DiscoveryQuickStart folder and choose "New File." In the dialog, select iOS > Resource > Property List. Name the file
adal_settings.plist
. Add the following keys to the list and set their values to those from your app registration. These are just examples; be sure to use your own values.
Key | Value |
---|---|
ClientId | Example: e59f95f8-7957-4c2e-8922-c1f27e1f14e0 |
RedirectUri | Example: https://my.client.app/ |
ResourceId | Example: https://api.office.com/discovery |
AuthorityUrl | https://login.microsoftonline.com/common/ |
- Open ViewController.m from the DiscoveryQuickStart folder. Add the umbrella header for Discovery and ADAL related headers.
#import <MSDiscovery.h>
#import <impl/ADALDependencyResolver.h>
#import <ADAuthenticationResult.h>
- Add properties for the ADALDependencyResolver and MSDiscoveryClient in the class extension section of ViewController.m.
@interface ViewController ()
@property (strong, nonatomic) ADALDependencyResolver *resolver;
@property (strong, nonatomic) MSDiscoveryClient *discoveryClient;
@end
- Initialize the resolver and client within the viewDidLoad method of the ViewController.m file.
- (void)viewDidLoad {
[super viewDidLoad];
self.resolver = [[ADALDependencyResolver alloc] initWithPlist];
self.discoveryClient = [[MSDiscoveryClient alloc] initWithUrl:@"https://api.office.com/discovery/v2.0/me" dependencyResolver:self.resolver];
}
- Before using the client, you must ensure the user has been logged on interactively at least once. You can use either
interactiveLogon
orinteractiveLogonWithCallback:
to initiate the logon sequence. In this exercise, add the following to the viewDidLoad method from the last step:
[self.resolver interactiveLogonWithCallback:^(ADAuthenticationResult *result) {
if (result.status == AD_SUCCEEDED) {
[self.resolver.logger logMessage:@"Connected." withLevel:LOG_LEVEL_INFO];
} else {
[self.resolver.logger logMessage:@"Authentication failed." withLevel:LOG_LEVEL_ERROR];
}
}];
- Now you can safely use the API client.
- O365-iOS-Connect - Getting started and authentication
- O365-iOS-Snippets - API requests and responses
You will need to sign a Contributor License Agreement before submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to submit a request via the form and then electronically sign the Contributor License Agreement when you receive the email containing the link to the document. This needs to only be done once for any Microsoft Open Technologies OSS project.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
Copyright (c) Microsoft, Inc. All rights reserved. Licensed under the Apache License, Version 2.0.