iOS apps

99 out of 118 rated this helpful - Rate this topic

Live Connect provides an API for the iOS operating system for Apple devices. The iOS API enables your iPad, iPhone, and iPod touch apps running on iOS 4.3 or higher to work with info in Outlook.com, Microsoft OneDrive, and other services that are compatible with Live Connect. Although you can still write code to call the Live Connect Representational State Transfer (REST) API directly, the iOS API now makes your coding tasks easier.

Note   If you're working on a mobile app that runs on Windows Phone, this isn't the topic you need. Go to Windows Phone apps.

Before you can start calling the Live Connect APIs, you need a client ID. For instructions, see Configuring your app.

Important  You must specify that your client ID is associated with mobile apps such as those for the iOS operating system for Apple devices. (Mobile apps use a different OAuth 2.0 authentication flow.) To do this, in the Live Connect app management site for your client ID, click Application Settings Page (or Edit settings, if you've already created your client ID), click API Settings, click Yes next to Mobile client app, and then click Save.

Prerequisites

The Live Connect iOS API requires Xcode 4.1 or later. Xcode 4.1 runs on Mac OS X Snow Leopard (version 10.6) and OS X Lion (version 10.7), while Xcode 4.2 runs only on OS X Lion (version 10.7).

Top

Referencing the iOS API with Objective-C

Before you can reference the Live Connect iOS API in an Xcode project, you must download the Live software development kit (SDK) for iOS. Here's how.

To download the Live SDK for iOS

You can now reference the iOS API.

To reference the iOS API

You can reference the iOS API in two ways. We recommend that you reference the iOS API framework. However, you can reference the iOS API source code directly if you need to modify it or want to see how it works.

To reference the iOS API framework

  1. Open your iOS project in Xcode, if you haven't already done so.
  2. In the Project Navigator, click your project.
  3. In the project editor, in the Targets area, click your project.
  4. Click Build Phases.
  5. Expand Link Binary With Libraries, and then click Add items (+).
  6. Click Add Other.
  7. Go to and select the LiveSDK.framework folder within the downloaded Live SDK for iOS, and then click Open.
  8. In the Project Navigator, drag the LiveSDK.framework node and drop it into Build Phases tab's Copy Bundle Resources table in the project editor.
  9. For each code file from which you want to reference the iOS API framework, add this import statement: #import "LiveSDK/LiveConnectClient.h".

Note  If you reference the iOS API framework, you will be able to browse the framework's type and member definitions from your Xcode project. However, you may have difficulty browsing the underlying implementation code of the types and members because this code is stored in binary format within the framework.

To reference the iOS API source code directly

  1. Open your iOS project in Xcode, if you haven't already done so.
  2. Click File > Add Files to "Your Project Name".
  3. Go to and select the Library folder within the downloaded Live SDK for iOS, and then click Add.
  4. For each code file from which you want to reference the API source code, add this import statement: #import "LiveConnectClient.h".

Note  If you reference the iOS API source code directly, you will be able to browse the underlying implementation code of the framework's types and members easily from your Xcode project. However, any changes that you make to this source code could result in design-time or run-time errors that are difficult to debug.

Important  If you reference the iOS API source code directly and you use Xcode 4.2 or later, you must disable Automatic Reference Counting (ARC). This is because the iOS API source code uses manual reference counting to enable the greatest number of developers using Xcode to reference the iOS API source code directly. If you want to use ARC, you must reference the iOS API framework by following the steps in the preceding section, or you must do an ARC conversion on the iOS API source code. To do an ARC conversion in Xcode:

  1. Follow the steps listed earlier in this section.
  2. On the Xcode menu, click Xcode > Preferences and select the Continue building after errors check box.
  3. On the Xcode menu, click Edit > Refactor > Convert to Objective-C ARC.
  4. Follow the on-screen directions.

Top

Code sample

To get you started, here's the basic code that shows how to reference the iOS APIs, invite a user to sign in, and get the signed-in user's permission to get his or her basic profile info.

ViewController.h


#import <UIKit/UIKit.h>
#import "LiveSDK/LiveConnectClient.h"

@interface ViewController : UIViewController<LiveAuthDelegate, LiveOperationDelegate, LiveDownloadOperationDelegate, LiveUploadOperationDelegate>
@property (strong, nonatomic) LiveConnectClient *liveClient;
@property (strong, nonatomic) IBOutlet UILabel *infoLabel;
@end


ViewController.m (where APP_CLIENT_ID is your app's client ID)


#import "ViewController.h"

@implementation ViewController
@synthesize liveClient;
@synthesize infoLabel;

NSString* APP_CLIENT_ID=@"000000004406774C";

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.liveClient = [[LiveConnectClient alloc] initWithClientId:APP_CLIENT_ID 
                                                         delegate:self 
                                                        userState:@"initialize"];
}

- (void)authCompleted:(LiveConnectSessionStatus) status 
              session:(LiveConnectSession *) session 
            userState:(id) userState
{
    if ([userState isEqual:@"initialize"])
    {
        [self.infoLabel setText:@"Initialized."];
        [self.liveClient login:self 
                        scopes:[NSArray arrayWithObjects:@"wl.signin", nil] 
                      delegate:self 
                     userState:@"signin"];
    }
    if ([userState isEqual:@"signin"])
    {
        if (session != nil)
        {
            [self.infoLabel setText:@"Signed in."];        
        }
    }
}

- (void)authFailed:(NSError *) error 
         userState:(id)userState
{
    [self.infoLabel setText:[NSString stringWithFormat:@"Error: %@", [error localizedDescription]]];
}
@end


Top

Configuring your app to participate in the Microsoft OneDrive app experience

There is a Microsoft OneDrive app that users can install on an iPhone or iPad device. They can then use this app to upload files to, or view files from, their OneDrive storage location. You can configure your app to participate in the file uploading and viewing experiences in the Microsoft OneDrive app. This can save you coding time and make for a better user experience.

In one scenario, a user can upload a file from your app to his or her OneDrive storage location by using the Microsoft OneDrive app. You don't have to write code in your app to upload the file directly; you can let the Microsoft OneDrive app upload the file instead. Here's how it works. When the user is viewing a file (like a document or a photo) within your app, you can let the user open the file in the Microsoft OneDrive app. Your app can use the UIDocumentInteractionController class to pass the file to the Microsoft OneDrive app, in which the user can then choose where to upload the file. After the Microsoft OneDrive app opens the file, the user taps the Upload command, taps the folder in his or her OneDrive location to upload the file to, and then the Microsoft OneDrive app uploads the file to that folder.

In another scenario, a user can use the Microsoft OneDrive app to view a file from his or her OneDrive storage location in your app. This enables a seamless user experience for viewing files, especially for custom file types that aren't associated with apps that might already be installed on the user's device. Here's how it works. In the Microsoft OneDrive app, the user taps the file to open it from his or her OneDrive location, and then taps the Open in Another App command that's displayed. The Microsoft OneDrive app then displays a list of apps that the user can choose from to view the file. If your app is registered to work with that file's type, your app appears in the list. When the user taps your app in the list, your app then displays that file.

For details about how your apps can participate in these experiences, see About Document Interaction in the iOS Developer Library documentation.

Top

Next steps

From here, we suggest that you continue your learning with the info in Core concepts, Identity API, Outlook.com API, and OneDrive API.

Top

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.