Connecting to Microsoft Office 365 is the first step every iOS app must take to start working with Office 365 services and data. This sample shows how to connect and then call one API through Microsoft Graph.
Note: For the Objective-C version of this sample, see O365-iOS-Microsoft-Graph-Connect.
-
Xcode version 8.2.1 from Apple
-
An Office 365 account. You can sign up for an Office 365 Developer subscription that includes the resources that you need to start building Office 365 apps.
Note: If you already have a subscription, the previous link sends you to a page with the message Sorry, you can’t add that to your current account. In that case, use an account from your current Office 365 subscription.
-
A client id (application id) of an application registered in Azure. This sample application must be granted the Send mail as a user permission for Microsoft Graph. To create the registration, see Grant permissions to the Connect application in Azure.
Note: The sample was tested on Xcode 9.1. This sample supports Xcode 8+ and iOS 10, which uses the Swift 3.0+ framework.
This sample demonstrates several REST calls to the Microsoft Graph REST endpoint.
- GETs the signed in user's profile photo from the user endpoint.
- PUT request to upload the profile photo to the user's OneDrive root folder
- POST a request to OneDrive to create a sharing link for a drive item to give other user's access to the uploaded photo
- POSTS a request to send a mail message with a photo attachment
- Clone this repository
- Install Carthage to import the Microsoft Authentication Library (MSAL) iOS dependency. Download the latest version of Carthage here.
The preview version of MSAL is distributed as source code using Carthage. To build the source code, do these steps:
- Open the Bash terminal and go to the app root folder.
- Create a cartfile: Copy
echo "github \"AzureAD/microsoft-authentication-library-for-objc\" \"master\"" > Cartfile
into the terminal and run the command. - Build the MSAL library: Copy
carthage update
into the terminal and run the command.
-
Open O365-iOS-Microsoft-Graph-Connect-Swift.xcworkspace
-
Open Info.plist as source code and update the client id:
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLName</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> <key>CFBundleURLSchemes</key> <array> <string>msalENTER_CLIENT_ID_HERE</string> <string>auth</string> </array> </dict> </array>
Note: If the "ENTER_CLIENT_ID_HERE" string in
CFBundleURLSchemes
array element 1 is not copied exactly as it exists in the Azure Portal app registration, the authentication redirect url is formed incorrectly. User authentication results are sent to http://localhost insted of the correct redirect url. Safari cannot connect to http://localhost on an iOS device.
For example,msal 3700a5ef-cee9-498e-a7e3-cbf701966331
includes a space betweenmsal
and the client id. This value forms an invalid redirect url.
- Run the sample.
If you'd like to contribute to this sample, see CONTRIBUTING.MD.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
We'd love to get your feedback about the Office 365 iOS Microsoft Graph Connect Swift project. You can send your questions and suggestions to us in the Issues section of this repository.
Questions about Microsoft Graph development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [MicrosoftGraph].
Copyright (c) 2017 Microsoft. All rights reserved.