Skip to content

iOS Sender App Development

tannyowen edited this page Dec 11, 2014 · 10 revisions

This overview shows how to build MatchStick sender applications for iOS using the MatchStick SDK. In this document, sender application refers to an iOS app running on a mobile device (the sender device), and receiver application refers to the receiver application running on the Flint device.

Setup

The MatchStcik SDK supports iOS version 6 and later

Download Library

Download the MatchStcik iOS Sender API library. See the MatchStcik iOS API Reference for descriptions of all classes and methods.

Xcode setup In your Xcode project, set the Other Linker Flags to -ObjC .

OtherLinkerFlags-ObjC

In your Xcode project, add the following framework libraries:

  • MatchStick framework
  • MediaAccessibility.framework (for iOS 6 and later)
  • CoreText.framework (for iOS 6 and later)
  • libicucore.dylib (for iOS 6 and later)
  • CFNetwork.framework (for iOS 6 and later)
  • Security.framework (for iOS 6 and later)
  • Foundation.framework (for iOS 6 and later)

framework libraries

Development

The MatchStick SDK uses the delegation pattern to inform the application of events and to move between various states of the Flint app life cycle.

Application flow

The following sections cover the details of the typical execution flow for a sender application:

  • Scan for devices
  • Select device
  • Launch application
  • Work with media channels
  • Load the media

Scan for devices

In this step, the sender application searches the WiFi network for MatchStick Flint receiver devices. This involves instantiating a device scanner, a delegate, and starting the scan. As the scanner discovers devices, it notifies the application via the delegate.

A MatchStick Flint receiver device is represented by a MSFKDevice class, which contains attributes like the device's IP address, friendly display name, model and manufacturer, and a URL to the device's display icon.

Typically, an application will run a scan for a fixed amount of time (for example, 5 seconds), and display a list of discovered devices to the user. The user will then select the device they wish to interact with from this list. To scan for flint enabled devices you must define a device scanner and register the delegate, then start scanning.

Device scanner

self.deviceScanner = [[MSFKDeviceScanner alloc] init];

[self.deviceScanner addListener:self];
[self.deviceScanner startScan];

After scanning begins, your delegate will be notified when devices are discovered or go offline.

For convenience, the device filter keeps track of all known active devices. This can be used to create an UIActionSheet for deploying devices to the user.

Showing devices in UIActionSheet

UIActionSheet *sheet = ...;

for ( MSFKDevice* device in deviceFilter.devices ){
    [sheet addButtonWithTitle:device.friendlyName];
}

[sheet showInView:myView];

Device selection

We need set Application's ID first. The Id can be one of them:

Start with "": which means this application will use some Flint internal specific features. Not start with "": Standard DIAL application ID.

Once the user has selected a device you can connect to it. Start by creating a device manager and give it the selected device. Next you register a delegate to listen for the connection.

MSFKDevice *selectedDevice = ...;

deviceManager = [[MSFKDeviceManager alloc]  initWithDevice:selectedDevice
clientPackageName:[info objectForKey:@"CFBundleIdentifier"]];

deviceManager.delegate = self;
self.deviceManager.appId = @"YOUR_APPLICATION_ID";
[self.deviceManager connect];

Launch application

Once you are connected to the receiver you will be notified. After successful connection you can launch your application.


#pragma mark - MSFKDeviceManagerDelegate
- (void)deviceManagerDidConnect:(MSFKDeviceManager *)deviceManager {
    NSLog(@"connected!!");

    [self.deviceManager launchApplication:@"APP_ID_HERE"];
}

Work with media channels

Media channels provide the means by which your sender app controls the playback on the receiver. You can also define custom channels to send custom messages to the receiver.

Media control channel

The media control channel plays, pauses, seeks, and stops the media on a receiver application. To use a media channel you must create an instance of MSFKMediaControlChannel after you connect to the flint application.


#pragma mark - MSFKDeviceManagerDelegate
- (void)deviceManager:(MSFKDeviceManager *)deviceManager
    didConnectToFlintApplication:(MSFKApplicationMetadata *)applicationMetadata
                      sessionID:(NSString *)sessionID
            launchedApplication:(BOOL)launchedApp {

  self.mediaControlChannel = [[MSFKMediaControlChannel alloc] init];
  self.mediaControlChannel.delegate = self;
  [self.deviceManager addChannel:self.mediaControlChannel];
}

Next, you must define the media you would like to flint by using the MSFKMediaMetadata class. See Media metadata, below.

Media metadata

Define the media you would like to flint by using the MSFKMediaMetadata class.

MSFKMediaMetadata *metadata = [[MSFKMediaMetadata alloc] init];

metadata.title = title;

[metadata addImage:[[MSFKImage alloc] initWithURL:thumbnailURL width:100 height:100]];

Finally you are ready to flint the media. You must create a MSFKMediaInformation that can be used to flint the media on the media control channel.

Load media

To load the media, do the following.

MSFKMediaInformation *mediaInformation =
    [[MSFKMediaInformation alloc] initWithContentID:[url absoluteString]
                                        streamType:MSFKMediaStreamTypeNone
                                       contentType:mimeType
                                          metadata:metaData
                                    streamDuration:123
                                        customData:nil];

[_mediaControlChannel loadMedia:mediaInformation autoplay:autoPlay playPosition:startTime];

Status updates

When multiple senders are connected to the same receiver, it is important for each sender to be aware of the changes in the receiver even if those changes were initiated from other senders. To this end, your application should register a MSFKMediaControlChannelDelegate. All of the connected senders will be notified through both the mediaControlChannelDidUpdateMetadata: and mediaControlChannelDidUpdateStatus: callbacks. In this case, the receiver SDK does not verify whether the new style is different from the previous one and notifies all the connected senders regardless. If, however, the list of active tracks is updated, only the mediaControlChannelDidUpdateStatus in connected senders will be notified.

Custom channel

Your sender can use a custom channel to send String messages to the receiver. Each custom channel is defined by a unique namespace and must start with the prefix urn:x-flint:, for example, urn:x-flint:com.example.custom. It is possible to have multiple custom channels, each with a unique namespace. The sender can work with a custom channel by creating a class that extends MSFKFlintChannel, and implements the didReceiveTextMessagemethod:

The sender can send a message to the receiver by using MSFKFlintChannel.sendTextMessage.

MyCustomChannel *textChannel = ...;
[self.textChannel sendTextMessage:[@"my text message"]];
Often an application will encode JSON messages into a String, then the receiver can decode the JSON string.

Logging

Use the MSFKLoggerDelegate to customize how you handle log messages.

@interface AppDelegate()  {
 ...
}

@end

@implementation AppDelegate

- (id)init {
 if (self = [super init]) {
   [MSFKLogger sharedInstance].delegate = self;
   ....
 }
 return self;
}

,,,

#pragma mark -MSFKLoggerDelegate

- (void)logFromFunction:(const char *)function message:(NSString *)message {
 // Process the log message here...
}

@end

  • Flint
    • [Developer's Guide](Developer Guide for Flint)
      • [Web Sender Apps](Web Sender App Development)
      • [Android Sender Apps](Android Sender App Development)
      • [iOS Sender Apps](iOS Sender App Development)
      • [Receiver Apps](Receiver Apps Development)
      • Chromecast App Porting
    • [API Libraries](API Libraries)
    • [Flint Protocol Docs](Flint Protocol Docs)
  • Matchstick
    • [Flashing Instructions](Flashing Instructions for Matchstick)
    • [Build Your Matchstick](Build Your Matchstick)
    • [Flashing Your Build](Flashing Your Build)
    • [Setup Your Matchstick](Setup Your Matchstick)
    • [Setup USB Mode](Setup USB Mode for Matchstick)
    • [Supported Media](Supported Media for Matchstick)

Clone this wiki locally