Windows (Phone) 8
NFC App Scenarios
Andreas Jakl, Mopius

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl
NFC Forum and the NFC Forum logo are trademarks of the Near Field Communication Forum.

1
Andreas Jakl
Twitter: @mopius
Email: andreas.jakl@mopius.com
Trainer & app developer
– mopius.com
– nfcinteractor.com

Nokia: Technology Wizard
FH Hagenberg, Mobile Computing: Assistant Professor
Siemens / BenQ Mobile: Augmented Reality-Apps
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

2
Near Field
Communication

Discover Your App

NDEF Library

Nfc Interactor

Share to Others

Seamless MultiUser Games &
Collaboration

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

3
PROXIMITY & TAPPING
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

4
NFC Scenarios

Connect Devices

Exchange Digital Objects

Acquire Content

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

5
Tap and Do
A gesture that is a natural interaction between people in close proximity used
to trigger doing something together between the devices they are holding.

System: Near Field Proximity
(e.g., NFC)

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl
Documentation: bit.ly/ProximitySpec

6
Proximity APIs
Windows Phone 8 +
Windows 8
Documentation
Win8: bit.ly/ProximityAPI
WP8: bit.ly/ProximityAPIwp8

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

7
APP SCENARIOS
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

8
Discover Your App

Share to Others

Seamless Multi-User
Games &
Collaboration

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

9
General Project Setup
1 Add Proximity Capability
2 Initialize ProximityDevice
_device = ProximityDevice.GetDefault();

Connect to HW
Detect devices in range
Publish & subscribe to messages

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

10
How to Launch Apps

either or

Win8 + WP8

Tag directly contains
app name and
custom data.
No registration necessary.

Custom URI scheme
launches app.
App needs to register.

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

11
parameters

platform 1

app name 1

platform 2

app name 2

…

Encoded into NDEF message*

Directly launch App
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl
* For your low-level interest: type: Absolute URI, type name format: windows.com/LaunchApp. Contents re-formatted, e.g., with string lengths before each value

12
Write LaunchApp Tags
1 Launch parameters, platforms + app IDs
// Arguments to pass to app, valid for all platforms
var launchArgs = "user=default";
// WP8: app's product id from the app manifest, wrapped in {}
var wp8App = "{5e506af4‐4586‐4c90‐bc5f‐428b12cf48bc}"; 
// Win8: app ID: Package.appxmanifest ‐> source ‐> <Application Id="...">
var win8AppId = "Proximity.App";
var win8App = Windows.ApplicationModel.Package.Current.Id.FamilyName +
"!" + win8AppId;
// Combine to LaunchApp Message
var launchAppMessage = launchArgs + 
"tWindowsPhonet" + wp8App + "tWindowst" + win8App;
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

13
Write LaunchApp Tags
2 Convert to byte array
var dataWriter = new Windows.Storage.Streams.DataWriter
{UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE};   
dataWriter.WriteString(launchAppMessage); 

3 Write to tags
_device.PublishBinaryMessage("LaunchApp:WriteTag",
dataWriter.DetachBuffer());

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

14
nearspeak: Good+morning.
Protocol
name

Custom data
Encoded Launch URI

Examples*
skype:mopius?call
spotify:search:17th%20boulevard

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl
* Definition & examples: http://en.wikipedia.org/wiki/URI_scheme

15
User Experience

No app installed

1 app installed

2+ apps installed

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

16
WP Protocol Association

Note: different
in Win8 / WP8

1 Specify protocol name in WMAppManifest.xml
...</Tokens>
Protocol
<Extensions>
name
<Protocol Name="nearspeak"
NavUriFragment="encodedLaunchUri=%s"
TaskID="_default" />
Fixed
</Extensions>

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

17
WP Protocol Association

Note: different
in Win8 / WP8

2 Create UriMapper class to parse parameters
class NearSpeakUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
// Example: "Protocol?encodedLaunchUri=nearspeak:Good+morning."
var tempUri = HttpUtility.UrlDecode(uri.ToString());
var launchContents = Regex.Match(tempUri, @"nearspeak:(.*)$").Groups[1].Value;
if (!String.IsNullOrEmpty(launchContents))
{
// Launched from associated "nearspeak:" protocol
// Call MainPage.xaml with parameters
return new Uri("/MainPage.xaml?ms_nfp_launchargs=" + launchContents, UriKind.Relative);
}
// Include the original URI with the mapping to the main page
return uri;
}}

Argument already handled in step 9 of LaunchApp
tags (MainPage.OnNavigatedTo)

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

18
WP Protocol Association
3 Use UriMapper in App.xaml.cs
(region:

)

private void InitializePhoneApplication() {
RootFrame = new PhoneApplicationFrame();
RootFrame.UriMapper = new NearSpeakUriMapper();
}

– If needed: launch protocol from app (for app2app comm)
await Windows.System.Launcher.LaunchUriAsync(
new Uri("nearspeak:Good+morning."));

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

19
Register for URI Schemes
Win 8

Specify URI scheme, display name + optional im

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

20
Tag Data After Launch
Win 8

Activtion arguments in App.xaml.cs
protected override async void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs protocolArgs = args as
ProtocolActivatedEventArgs;
}
}

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

21
User Experience
Win 8

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

22
Discover Your App

Share to Others

Seamless Multi-User
Games &
Collaboration

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

23
Publish Messages
1 Start publishing
_publishingMessageId = _device.PublishUriMessage(
new Uri("nfcinteractor:compose"));

Proximity devices only
– (doesn’t write tags)

Contains
scheme,
platform &
App ID

Windows Protocol + URI record
– Encapsulated in NDEF

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

24
Write Tags
1 Prepare & convert data
var dataWriter = 
new Windows.Storage.Streams.DataWriter { 
UnicodeEncoding = Windows.Storage.Streams.
UnicodeEncoding.Utf16LE};
dataWriter.WriteString("nfcinteractor:compose");
var dataBuffer = dataWriter.DetachBuffer();

Mandatory
encoding

2 Write tag (no device publication)
_device.PublishBinaryMessage("WindowsUri:WriteTag", dataBuffer);

bit.ly/PublishTypes
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

25
Discover Your App

Share to Others

Seamless Multi-User
Games &
Collaboration

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

26
Seamless MultiUser Games &
Collaboration

Tap for

Quick Data
Exchange

Long Term
Connection

ProximityDevice

PeerFinder

Exchange Windows /
NDEF messages,
SNEP protocol

Automatically builds
Bt / WiFi Direct
socket connection

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

27
Establishing

Trigger

Long Term
Connection
Browse

Interact with Tap

Start Search

NFC

Bt, WiFi, etc.

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

28
Tap to Trigger

App not installed

App installed
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

29
Connection State
Proximity gesture complete
Devices can be pulled away

Which device initiated tap gesture?
→ Connecting, other device Listening

1
PeerFound

2
Connecting /
Listening

Access socket of persistent transport
(e.g., TCP/IP, Bt)

3
Completed

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

30
Find Peers
1 Start waiting for triggered connections
PeerFinder.TriggeredConnectionStateChanged +=
TriggeredConnectionStateChanged;
PeerFinder.Start();

2 Peer found & connection established? Send message over socket
private async void TriggeredConnectionStateChanged(object sender, 
TriggeredConnectionStateChangedEventArgs eventArgs) {
if (eventArgs.State == TriggeredConnectState.Completed) {
// Socket connection established!
var dataWriter = new DataWriter(eventArgs.Socket.OutputStream);
dataWriter.WriteString("Hello Peer!");
var numBytesWritten = await dataWriter.StoreAsync();
3
}}
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl
* For URI records + simple Smart Poster (w/o title), use the WindowsUri type.

31
Completed
TOOLS & RESOURCES
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

32
UX Recommendations*
User initiated peer
search only

Ask for consent

Show connection
state

Failed
connection?
Inform & revert to
single-user mode

Let user get out of
proximity
experience

Proximity: only if
connection details
not relevant

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl
* bit.ly/ProximityUX

33
NFC Tools
Proximity Tapper for WP emulator
– http://proximitytapper.codeplex.com/

Open NFC Simulator
– http://open-nfc.org/wp/editions/android/

NFC plugin for Eclipse: NDEF Editor
– https://code.google.com/p/nfc-eclipse-plugin/
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

34
nfcinteractor.com

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

35
NFC Resources
 NFC News: nfcworld.com
 NFC developer comparison
(WP, Android, BlackBerry):
bit.ly/NfcDevCompare
 Specifications: nfc-forum.org
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

36
Standardized NFC Tag Contents

NDEF HANDLING
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

37
NFC Data
NDEF Record
(e.g., URL)

…

NDEF Message
NDEF = NFC Data Exchange Format

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

38
SNEP = Simple NDEF Exchange Protocol
NDEF Record
(e.g., URL)

…

NDEF Message

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

39
Reading NDEF
1 Subscribe to all NDEF messages
_subscribedMessageId = _device.SubscribeForMessage(
"NDEF", MessageReceivedHandler);

2 Parse raw byte array in handler 

http://www.nfc-forum.org/specs/

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

40
Reading NDEF
// Convert the language code to a byte array

Simple example:
assembling payload of Text record

1 Subscribe to all NDEF messages= Encoding.UTF8;
var languageEncoding

var encodedLanguage = languageEncoding.GetBytes(languageCode);
// Encode and convert the text to a byte array
var encoding = (textEncoding == TextEncodingType.Utf8) ? Encoding.UTF8 : Encoding.BigEndianUnicode;
var encodedText = encoding.GetBytes(text);
// Calculate the length of the payload & create the array
var payloadLength = 1 + encodedLanguage.Length + encodedText.Length;
Payload = new byte[payloadLength];

_subscribedMessageId = _device.SubscribeForMessage(
"NDEF", MessageReceivedHandler);

2 Parse raw byte array in handler 

// Assemble the status byte
Payload[0] = 0; // Make sure also the RFU bit is set to 0
// Text encoding
if (textEncoding == TextEncodingType.Utf8)
Payload[0] &= 0x7F; // ~0x80
else
Payload[0] |= 0x80;

http://www.nfc-forum.org/specs/

// Language code length
Payload[0] |= (byte)(0x3f & (byte)encodedLanguage.Length);
// Language code
Array.Copy(encodedLanguage, 0, Payload, 1, encodedLanguage.Length);
// Text
Array.Copy(encodedText, 0, Payload, 1 + encodedLanguage.Length, encodedText.Length);

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

41
NDEF.codeplex.com
Create NDEF
messages & records
(standard compliant)

Reusable
NDEF classes

Parse information
from raw byte arrays

Fully documented
Open Source LGPL license
(based on Qt Mobility)

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

42
NDEF Subscriptions
1 Subscribe to all NDEF formatted tags
_subscribedMessageId = _device.SubscribeForMessage("NDEF",
MessageReceivedHandler);

2 Parse NDEF message
private void MessageReceivedHandler(ProximityDevice sender, 
ProximityMessage message)
{
var msgArray = message.Data.ToArray();
NdefMessage ndefMessage = NdefMessage.FromByteArray(msgArray);
[...]
}
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

43
NDEF Subscriptions
3 Analyze all contained NDEF records with specialized classes
foreach (NdefRecord record in ndefMessage) 
{
Debug.WriteLine("Record type: " + 
Encoding.UTF8.GetString(record.Type, 0, record.Type.Length));
// Check the type of each record ‐ handling a Smart Poster in this example
if (record.CheckSpecializedType(false) == typeof(NdefSpRecord)) 
{
// Convert and extract Smart Poster info
var spRecord = new NdefSpRecord(record);
Debug.WriteLine("URI: " + spRecord.Uri);
Debug.WriteLine("Titles: " + spRecord.TitleCount());
Debug.WriteLine("1. Title: " + spRecord.Titles[0].Text);
Debug.WriteLine("Action set: " + spRecord.ActionInUse());
}
}
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

44
Write NDEF
1 Prepare & convert data
// Initialize Smart Poster record with URI, Action + 1 Title
var spRecord = new NdefSpRecord
{ Uri = "http://www.nfcinteractor.com" };
spRecord.AddTitle(new NdefTextRecord
{ Text = "Nfc Interactor", LanguageCode = "en" });
// Add record to NDEF message
var msg = new NdefMessage { spRecord };

2a Write tag
// Publish NDEF message to a tag
_device.PublishBinaryMessage("NDEF:WriteTag", msg.ToByteArray().AsBuffer());

2b Publish to devices
// Alternative: send NDEF message to another NFC device
_device.PublishBinaryMessage("NDEF", msg.ToByteArray().AsBuffer());
Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

45
Supported Record Types
Smart Poster
URI
Text
LaunchApp
Android Application Record (AAR)
Windows Phone Settings
Nokia Accessories Record
NearSpeak Voice Messages

Geo tags
Social tags
SMS tags
Telephone call
Mailto tags

ndef.mopius.com

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

46
Near Field
Communication

Discover Your App

NDEF Library

Nfc Interactor

Share to Others

Seamless MultiUser Games &
Collaboration

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

47
Thank You.
Andreas Jakl
@mopius
mopius.com
nfcinteractor.com

Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl

48

Windows (Phone) 8 NFC App Scenarios

  • 1.
    Windows (Phone) 8 NFCApp Scenarios Andreas Jakl, Mopius Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl NFC Forum and the NFC Forum logo are trademarks of the Near Field Communication Forum. 1
  • 2.
    Andreas Jakl Twitter: @mopius Email:andreas.jakl@mopius.com Trainer & app developer – mopius.com – nfcinteractor.com Nokia: Technology Wizard FH Hagenberg, Mobile Computing: Assistant Professor Siemens / BenQ Mobile: Augmented Reality-Apps Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 2
  • 3.
    Near Field Communication Discover YourApp NDEF Library Nfc Interactor Share to Others Seamless MultiUser Games & Collaboration Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 3
  • 4.
    PROXIMITY & TAPPING Windows(Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 4
  • 5.
    NFC Scenarios Connect Devices ExchangeDigital Objects Acquire Content Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 5
  • 6.
    Tap and Do Agesture that is a natural interaction between people in close proximity used to trigger doing something together between the devices they are holding. System: Near Field Proximity (e.g., NFC) Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl Documentation: bit.ly/ProximitySpec 6
  • 7.
    Proximity APIs Windows Phone8 + Windows 8 Documentation Win8: bit.ly/ProximityAPI WP8: bit.ly/ProximityAPIwp8 Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 7
  • 8.
    APP SCENARIOS Windows (Phone)8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 8
  • 9.
    Discover Your App Shareto Others Seamless Multi-User Games & Collaboration Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 9
  • 10.
    General Project Setup 1Add Proximity Capability 2 Initialize ProximityDevice _device = ProximityDevice.GetDefault(); Connect to HW Detect devices in range Publish & subscribe to messages Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 10
  • 11.
    How to LaunchApps either or Win8 + WP8 Tag directly contains app name and custom data. No registration necessary. Custom URI scheme launches app. App needs to register. Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 11
  • 12.
    parameters platform 1 app name1 platform 2 app name 2 … Encoded into NDEF message* Directly launch App Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl * For your low-level interest: type: Absolute URI, type name format: windows.com/LaunchApp. Contents re-formatted, e.g., with string lengths before each value 12
  • 13.
    Write LaunchApp Tags 1Launch parameters, platforms + app IDs // Arguments to pass to app, valid for all platforms var launchArgs = "user=default"; // WP8: app's product id from the app manifest, wrapped in {} var wp8App = "{5e506af4‐4586‐4c90‐bc5f‐428b12cf48bc}";  // Win8: app ID: Package.appxmanifest ‐> source ‐> <Application Id="..."> var win8AppId = "Proximity.App"; var win8App = Windows.ApplicationModel.Package.Current.Id.FamilyName + "!" + win8AppId; // Combine to LaunchApp Message var launchAppMessage = launchArgs +  "tWindowsPhonet" + wp8App + "tWindowst" + win8App; Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 13
  • 14.
    Write LaunchApp Tags 2Convert to byte array var dataWriter = new Windows.Storage.Streams.DataWriter {UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE};    dataWriter.WriteString(launchAppMessage);  3 Write to tags _device.PublishBinaryMessage("LaunchApp:WriteTag", dataWriter.DetachBuffer()); Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 14
  • 15.
    nearspeak: Good+morning. Protocol name Custom data EncodedLaunch URI Examples* skype:mopius?call spotify:search:17th%20boulevard Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl * Definition & examples: http://en.wikipedia.org/wiki/URI_scheme 15
  • 16.
    User Experience No appinstalled 1 app installed 2+ apps installed Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 16
  • 17.
    WP Protocol Association Note:different in Win8 / WP8 1 Specify protocol name in WMAppManifest.xml ...</Tokens> Protocol <Extensions> name <Protocol Name="nearspeak" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" /> Fixed </Extensions> Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 17
  • 18.
    WP Protocol Association Note:different in Win8 / WP8 2 Create UriMapper class to parse parameters class NearSpeakUriMapper : UriMapperBase { public override Uri MapUri(Uri uri) { // Example: "Protocol?encodedLaunchUri=nearspeak:Good+morning." var tempUri = HttpUtility.UrlDecode(uri.ToString()); var launchContents = Regex.Match(tempUri, @"nearspeak:(.*)$").Groups[1].Value; if (!String.IsNullOrEmpty(launchContents)) { // Launched from associated "nearspeak:" protocol // Call MainPage.xaml with parameters return new Uri("/MainPage.xaml?ms_nfp_launchargs=" + launchContents, UriKind.Relative); } // Include the original URI with the mapping to the main page return uri; }} Argument already handled in step 9 of LaunchApp tags (MainPage.OnNavigatedTo) Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 18
  • 19.
    WP Protocol Association 3Use UriMapper in App.xaml.cs (region: ) private void InitializePhoneApplication() { RootFrame = new PhoneApplicationFrame(); RootFrame.UriMapper = new NearSpeakUriMapper(); } – If needed: launch protocol from app (for app2app comm) await Windows.System.Launcher.LaunchUriAsync( new Uri("nearspeak:Good+morning.")); Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 19
  • 20.
    Register for URISchemes Win 8 Specify URI scheme, display name + optional im Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 20
  • 21.
    Tag Data AfterLaunch Win 8 Activtion arguments in App.xaml.cs protected override async void OnActivated(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Protocol) { ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs; } } Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 21
  • 22.
    User Experience Win 8 Windows(Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 22
  • 23.
    Discover Your App Shareto Others Seamless Multi-User Games & Collaboration Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 23
  • 24.
    Publish Messages 1 Startpublishing _publishingMessageId = _device.PublishUriMessage( new Uri("nfcinteractor:compose")); Proximity devices only – (doesn’t write tags) Contains scheme, platform & App ID Windows Protocol + URI record – Encapsulated in NDEF Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 24
  • 25.
    Write Tags 1 Prepare& convert data var dataWriter =  new Windows.Storage.Streams.DataWriter {  UnicodeEncoding = Windows.Storage.Streams. UnicodeEncoding.Utf16LE}; dataWriter.WriteString("nfcinteractor:compose"); var dataBuffer = dataWriter.DetachBuffer(); Mandatory encoding 2 Write tag (no device publication) _device.PublishBinaryMessage("WindowsUri:WriteTag", dataBuffer); bit.ly/PublishTypes Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 25
  • 26.
    Discover Your App Shareto Others Seamless Multi-User Games & Collaboration Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 26
  • 27.
    Seamless MultiUser Games& Collaboration Tap for Quick Data Exchange Long Term Connection ProximityDevice PeerFinder Exchange Windows / NDEF messages, SNEP protocol Automatically builds Bt / WiFi Direct socket connection Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 27
  • 28.
    Establishing Trigger Long Term Connection Browse Interact withTap Start Search NFC Bt, WiFi, etc. Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 28
  • 29.
    Tap to Trigger Appnot installed App installed Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 29
  • 30.
    Connection State Proximity gesturecomplete Devices can be pulled away Which device initiated tap gesture? → Connecting, other device Listening 1 PeerFound 2 Connecting / Listening Access socket of persistent transport (e.g., TCP/IP, Bt) 3 Completed Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 30
  • 31.
    Find Peers 1 Startwaiting for triggered connections PeerFinder.TriggeredConnectionStateChanged += TriggeredConnectionStateChanged; PeerFinder.Start(); 2 Peer found & connection established? Send message over socket private async void TriggeredConnectionStateChanged(object sender,  TriggeredConnectionStateChangedEventArgs eventArgs) { if (eventArgs.State == TriggeredConnectState.Completed) { // Socket connection established! var dataWriter = new DataWriter(eventArgs.Socket.OutputStream); dataWriter.WriteString("Hello Peer!"); var numBytesWritten = await dataWriter.StoreAsync(); 3 }} Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl * For URI records + simple Smart Poster (w/o title), use the WindowsUri type. 31 Completed
  • 32.
    TOOLS & RESOURCES Windows(Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 32
  • 33.
    UX Recommendations* User initiatedpeer search only Ask for consent Show connection state Failed connection? Inform & revert to single-user mode Let user get out of proximity experience Proximity: only if connection details not relevant Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl * bit.ly/ProximityUX 33
  • 34.
    NFC Tools Proximity Tapperfor WP emulator – http://proximitytapper.codeplex.com/ Open NFC Simulator – http://open-nfc.org/wp/editions/android/ NFC plugin for Eclipse: NDEF Editor – https://code.google.com/p/nfc-eclipse-plugin/ Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 34
  • 35.
    nfcinteractor.com Windows (Phone) 8NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 35
  • 36.
    NFC Resources  NFCNews: nfcworld.com  NFC developer comparison (WP, Android, BlackBerry): bit.ly/NfcDevCompare  Specifications: nfc-forum.org Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 36
  • 37.
    Standardized NFC TagContents NDEF HANDLING Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 37
  • 38.
    NFC Data NDEF Record (e.g.,URL) … NDEF Message NDEF = NFC Data Exchange Format Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 38
  • 39.
    SNEP = SimpleNDEF Exchange Protocol NDEF Record (e.g., URL) … NDEF Message Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 39
  • 40.
    Reading NDEF 1 Subscribeto all NDEF messages _subscribedMessageId = _device.SubscribeForMessage( "NDEF", MessageReceivedHandler); 2 Parse raw byte array in handler  http://www.nfc-forum.org/specs/ Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 40
  • 41.
    Reading NDEF // Convert the language code to a byte array Simple example: assemblingpayload of Text record 1 Subscribe to all NDEF messages= Encoding.UTF8; var languageEncoding var encodedLanguage = languageEncoding.GetBytes(languageCode); // Encode and convert the text to a byte array var encoding = (textEncoding == TextEncodingType.Utf8) ? Encoding.UTF8 : Encoding.BigEndianUnicode; var encodedText = encoding.GetBytes(text); // Calculate the length of the payload & create the array var payloadLength = 1 + encodedLanguage.Length + encodedText.Length; Payload = new byte[payloadLength]; _subscribedMessageId = _device.SubscribeForMessage( "NDEF", MessageReceivedHandler); 2 Parse raw byte array in handler  // Assemble the status byte Payload[0] = 0; // Make sure also the RFU bit is set to 0 // Text encoding if (textEncoding == TextEncodingType.Utf8) Payload[0] &= 0x7F; // ~0x80 else Payload[0] |= 0x80; http://www.nfc-forum.org/specs/ // Language code length Payload[0] |= (byte)(0x3f & (byte)encodedLanguage.Length); // Language code Array.Copy(encodedLanguage, 0, Payload, 1, encodedLanguage.Length); // Text Array.Copy(encodedText, 0, Payload, 1 + encodedLanguage.Length, encodedText.Length); Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 41
  • 42.
    NDEF.codeplex.com Create NDEF messages &records (standard compliant) Reusable NDEF classes Parse information from raw byte arrays Fully documented Open Source LGPL license (based on Qt Mobility) Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 42
  • 43.
    NDEF Subscriptions 1 Subscribeto all NDEF formatted tags _subscribedMessageId = _device.SubscribeForMessage("NDEF", MessageReceivedHandler); 2 Parse NDEF message private void MessageReceivedHandler(ProximityDevice sender,  ProximityMessage message) { var msgArray = message.Data.ToArray(); NdefMessage ndefMessage = NdefMessage.FromByteArray(msgArray); [...] } Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 43
  • 44.
    NDEF Subscriptions 3 Analyzeall contained NDEF records with specialized classes foreach (NdefRecord record in ndefMessage)  { Debug.WriteLine("Record type: " +  Encoding.UTF8.GetString(record.Type, 0, record.Type.Length)); // Check the type of each record ‐ handling a Smart Poster in this example if (record.CheckSpecializedType(false) == typeof(NdefSpRecord))  { // Convert and extract Smart Poster info var spRecord = new NdefSpRecord(record); Debug.WriteLine("URI: " + spRecord.Uri); Debug.WriteLine("Titles: " + spRecord.TitleCount()); Debug.WriteLine("1. Title: " + spRecord.Titles[0].Text); Debug.WriteLine("Action set: " + spRecord.ActionInUse()); } } Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 44
  • 45.
    Write NDEF 1 Prepare& convert data // Initialize Smart Poster record with URI, Action + 1 Title var spRecord = new NdefSpRecord { Uri = "http://www.nfcinteractor.com" }; spRecord.AddTitle(new NdefTextRecord { Text = "Nfc Interactor", LanguageCode = "en" }); // Add record to NDEF message var msg = new NdefMessage { spRecord }; 2a Write tag // Publish NDEF message to a tag _device.PublishBinaryMessage("NDEF:WriteTag", msg.ToByteArray().AsBuffer()); 2b Publish to devices // Alternative: send NDEF message to another NFC device _device.PublishBinaryMessage("NDEF", msg.ToByteArray().AsBuffer()); Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 45
  • 46.
    Supported Record Types SmartPoster URI Text LaunchApp Android Application Record (AAR) Windows Phone Settings Nokia Accessories Record NearSpeak Voice Messages Geo tags Social tags SMS tags Telephone call Mailto tags ndef.mopius.com Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 46
  • 47.
    Near Field Communication Discover YourApp NDEF Library Nfc Interactor Share to Others Seamless MultiUser Games & Collaboration Windows (Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 47
  • 48.
    Thank You. Andreas Jakl @mopius mopius.com nfcinteractor.com Windows(Phone) 8 NFC App Scenarios v3.0.0 © 2014 Andreas Jakl 48