Latest 0.8.0
Homepage https://github.com/OfficeDev/Microsoft-Graph-SDK-iOS
License Apache License, Version 2.0
Platforms ios 8.0, requires ARC
Dependencies orc, ADALiOS, LiveSDK
Authors

Microsoft Graph SDK for iOS (preview)

Microsoft Graph (previously called Office 365 unified API) exposes multiple APIs from Microsoft cloud services through a single REST API endpoint (Microsoft Graph API endpoint v1.0). Using Microsoft Graph, you can turn formerly difficult or complex queries into simple navigations.
Easily integrate services and data from Microsoft Graph into native iOS apps using this Objective-C library.


:exclamation:NOTE: This code and associated binaries are released as a developer PREVIEW. You are free to use this library according to the terms of its included LICENSE and to open issues in this repo for unofficial support.

Information about official Microsoft support is available here.


This library is generated from the Microsoft Graph API metadata using Vipr and Vipr-T4TemplateWriter and uses a shared client stack.

Quick Start

To use this library in your project, follow these general steps, as described further below:

  1. Configure a Podfile.
  2. Set up authentication.
  3. Construct an API client.

Setup

  1. 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 MSGraphQuickStart here.

  2. Add a file to the project. Choose iOS > Other > Empty from the dialog and name your file Podfile.

  3. Add these lines to the Podfile to import the Microsoft Graph SDK

    source 'https://github.com/CocoaPods/Specs.git'
    xcodeproj 'MSGraphQuickStart'
    pod 'MSGraph-SDK-iOS'

    NOTE: For detailed information on CocoaPods and best practices for Podfiles, read the Using CocoaPods guide.

  4. Close the Xcode project.

  5. From the command line, change to your project’s directory. Then run pod install.

    NOTE: Install CocoaPods first of course. Instructions here.

  6. From the same location in the terminal, execute open MSGraphQuickStart.xcworkspace to open a workspace containing your original project together with imported pods in Xcode.

Authenticate and construct client

With your project prepared, the next step is to initialize the dependency manager and an API client.

exclamation: 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][MSDN Add Common Consent].

  1. Right-click the MSGraphQuickStart 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://graph.microsoft.com
    AuthorityUrl https://login.microsoftonline.com/common/
  2. Open ViewController.m from the MSGraphQuickStart folder. Add the umbrella header for Microsoft Graph and ADAL related headers.

    #import <MSGraphService.h>
    #import <impl/ADALDependencyResolver.h>
    #import <ADAuthenticationResult.h>
  3. Add properties for the ADALDependencyResolver and MSGraph in the class extension section of ViewController.m.

    @interface ViewController ()
    
    @property (strong, nonatomic) ADALDependencyResolver *resolver;
    @property (strong, nonatomic) MSGraphServiceClient *graphClient;
    
    @end
  4. Initialize the resolver and client within the viewDidLoad method of the ViewController.m file.

    - (void)viewDidLoad {
     [super viewDidLoad];
    
    self.resolver = [[ADALDependencyResolver alloc] initWithPlist];
    
    self.graphClient = [[MSGraphServiceClient alloc] initWithUrl:@"https://graph.microsoft.com/" dependencyResolver:self.resolver];
    }
  5. Before using the client, you must ensure the user has been logged on interactively at least once. You can use either interactiveLogon or interactiveLogonWithCallback: 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];
     }
    }];
  6. Now you can safely use the API client.

Samples

  • [O365-iOS-Connect] – Getting started and authentication
  • [O365-iOS-Snippets] – API requests and responses

Contributing

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.

License

Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0.

Latest podspec

{
    "name": "MSGraph-SDK-iOS",
    "version": "0.8.0",
    "summary": "Client libraries for calling Microsoft Graph APIs from iOS apps. (Preview)",
    "description": "Client libraries for calling Microsoft Graph APIs from iOS apps. (Preview)",
    "homepage": "https://github.com/OfficeDev/Microsoft-Graph-SDK-iOS",
    "license": "Apache License, Version 2.0",
    "authors": {
        "v-migpe": "[email protected]"
    },
    "social_media_url": "http://twitter.com/OpenAtMicrosoft",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/OfficeDev/Microsoft-Graph-SDK-iOS.git",
        "tag": "v0.8.0"
    },
    "exclude_files": "**/Build/**/*",
    "requires_arc": true,
    "source_files": [
        "Fetchers/*.{h,m}",
        "Model/*.{h,m}",
        "MSGraphService.h"
    ],
    "dependencies": {
        "orc": [],
        "ADALiOS": [
            "=1.2.4"
        ],
        "LiveSDK": [
            "=5.6.1"
        ]
    }
}

Pin It on Pinterest

Share This