# The Emmoco Mobile Framework iOS examples

## Introduction

These examples demonstrate use of Emmoco’s Mobile Framework for iOS.  Each example shows a different aspect of mobile to embedded system communication.

NOTE: BLE is no longer supported by the iOS simulator.  These examples cannot be built for the i386 architecture.

There are five examples:

a) FirstApp - Connecting to a device and writing a value
b) Compound - Dealing with more complicated resource types
c) Indicator - Receiving notifications from the embedded system to your application
d) File - Dealing with file resources
e) Broadcast - Receiving information from embedded systems while not connected

These examples correspond to their counterparts in the embedded system examples.  

## Before you begin

This document and these examples assume a basic understanding of iOS, Emmoco’s embedded platform, and Bluetooth Low Energy.  To successfully run these iOS examples, you will need their counterparts running on an embedded system.

## FirstApp - The “Hello world” of mobile to embedded communication

This example demonstrates scanning, connecting, and writing a value to an embedded system.

Before connecting to a device, you must “discover” it through scanning.  The pattern for this is demonstrated in the class `EMDevicePickerViewController`.  This class observes the `devices` property on `EMConnectionListManager` and displays discovered devices in a table.  When the user selects a device, this class connects to the device by interacting with `EMConnectionManager`.

Once connected, the class `EMFirstAppViewController` demonstrates how to write values to the embedded system through an interface control.  In this case, a UISlider writes a number down when its value changes.

## Compound

This example is similar to the FirstApp example, but demonstrates the reading and writing of a more complex data type.  All resources on the embedded system correspond to Foundation objects in iOS.

`NSNumber` - floats, integers
`NSString` - enums, strings
`NSArray` - Arrays
`NSDictionary` - Structs
`NSData` - files

In FirstApp, we used `NSNumber` to write to a number.  In this example, we’re using an `NSDictionary` to read and write structs.

## Indicator

Indicators are notifications that come from the embedded system up to your mobile application.  The Mobile Framework delivers these events to you through `NSNotificationCenter`.  The Indicator example shows you how to read and process these notifications.

See `EMIndicatorExampleViewController` for how to do this.

## File

Files are often very large, requiring multiple packets to transfer them to and from the embedded system.  Fortunately, the Mobile Framework handles this for you.  When reading a file, you are given an `NSData` object only after the entire transfer is complete.  To write a value, you hand an `NSData` object to the framework.

## Broadcast

This is the only example that does not ever connect to the embedded system.  Instead, it pulls a resource’s value from the device’s advertise packet.  See `EMBroadcastViewController` to understand how this works.
