{"_id":"576d42354bcd290e00428949","parentDoc":null,"__v":5,"category":{"_id":"576d42354bcd290e00428946","__v":0,"version":"576d42354bcd290e00428941","project":"56a526d4e7a1622b0024fae4","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-16T13:36:01.427Z","from_sync":false,"order":3,"slug":"guides","title":"Guides"},"project":"56a526d4e7a1622b0024fae4","version":{"_id":"576d42354bcd290e00428941","project":"56a526d4e7a1622b0024fae4","__v":1,"createdAt":"2016-06-24T14:22:45.076Z","releaseDate":"2016-06-24T14:22:45.076Z","categories":["576d42354bcd290e00428942","576d42354bcd290e00428943","576d42354bcd290e00428944","576d42354bcd290e00428945","576d42354bcd290e00428946","576d42354bcd290e00428947"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2"},"user":"56703859e10ecb0d0004eebb","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-22T11:08:38.708Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"This guide walks you through the Chirp Gem Swap app which is included in our [iOS SDK download](https://admin.chirp.io/sign_up/create_profile). \n\nChirp Gem Swap works completely offline by encoding the information it needs to send within the acoustic identifier.\n\nThis demo shows how small packages of data can be sent over the audio only using our SDK.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/7EHmVD4MROOQf9xxDqoj_Screenshot%202016-02-23%2015.23.11.png\",\n        \"Screenshot 2016-02-23 15.23.11.png\",\n        \"1115\",\n        \"804\",\n        \"#3eb0f5\",\n        \"\"\n      ],\n      \"caption\": \"The iOS SDK download folder layout\"\n    }\n  ]\n}\n[/block]\nIt's probably easiest if you have that open as we go - if you do not already have a copy you can download or apply to become a Chirp developer [here](https://admin.chirp.io).\n\nThe first thing we need to do is insert your app key and secret to uniquely identify your app on our systems. Get your key and secret [here](https://admin.chirp.io).\n\nOnce you have them, insert them in the correct lines of ViewController.m\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/g5X9ybbhQvecokMBcQzY_Screenshot%202016-07-01%2009.54.36.png\",\n        \"Screenshot 2016-07-01 09.54.36.png\",\n        \"1152\",\n        \"242\",\n        \"#d4774f\",\n        \"\"\n      ],\n      \"caption\": \"Replace your app key and secret at the top of the ViewController.m source file.\"\n    }\n  ]\n}\n[/block]\nAt this point, you should be able to build and run the app in the simulator or attached device by pressing `⌘R`\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/CWMtX6fPSm6pBXP6oASC_Simulator%20Screen%20Shot%2023%20Feb%202016,%2015.26.23.png\",\n        \"Simulator Screen Shot 23 Feb 2016, 15.26.23.png\",\n        \"310\",\n        \"552\",\n        \"#69af80\",\n        \"\"\n      ],\n      \"caption\": \"You should be able to run this simple single-screen app.\"\n    }\n  ]\n}\n[/block]\nYou can run the app on both the simulator and an attached device, or two devices if you have them. This will allow you to chirp messages between the two apps:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/EG0lC48hQ0qJe9pqTQQq_Desktop.png\",\n        \"Desktop.png\",\n        \"1024\",\n        \"764\",\n        \"#67b16c\",\n        \"\"\n      ],\n      \"caption\": \"Chirping gems between two apps.\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"How it works\"\n}\n[/block]\n# Sending the gem\n\nGem Swap encodes the position, rotation and colour of each gem in the acoustic identifier that is broadcast through the sender's loudspeaker. \n\nEach identifier has 10 digits, so we are able to encode the parameters as follows:\n\n```\n[3 characters : X position (percentage)]\n[3 characters : Y position (percentage)]\n[1 characters : gem colour]\n[3 characters : rotation]\n```\n\nThis takes place inside GemView.m in the `toShortcode` method.\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/XFthuaBHQB2dzcqRH8Be_Screenshot%202016-02-23%2015.42.19.png\",\n        \"Screenshot 2016-02-23 15.42.19.png\",\n        \"687\",\n        \"239\",\n        \"#39b47a\",\n        \"\"\n      ],\n      \"caption\": \"Our method for encoding the gems characteristics into a identifier\",\n      \"sizing\": \"full\"\n    }\n  ]\n}\n[/block]\nSo a yellow gem (colour 3) at position 0, 100 with 20 degrees rotation would be encoded as\n```\n000 100 3 020\n```\n\nand passed to the SDK as:\n```\n:::at:::\"0001003020\"\n```\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/W11aZD6RfCsdQpmUcX7N_Screenshot%202016-07-01%2009.56.16.png\",\n        \"Screenshot 2016-07-01 09.56.16.png\",\n        \"1162\",\n        \"548\",\n        \"#2fbd9d\",\n        \"\"\n      ],\n      \"caption\": \"Chirping our identifier\",\n      \"sizing\": \"full\"\n    }\n  ]\n}\n[/block]\n# Receiving the message\n\nReceiving the message is just as simple.\n\nWe use the `setChirpHeardBlock:` completion handler to parse any chirps that we hear and handle any errors that occur during transmission.\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/3aSL0e9FRjS33ejPJsat_Screenshot%202016-07-01%2009.59.24.png\",\n        \"Screenshot 2016-07-01 09.59.24.png\",\n        \"1131\",\n        \"746\",\n        \"#2dba99\",\n        \"\"\n      ],\n      \"sizing\": \"full\"\n    }\n  ]\n}\n[/block]\nAs soon as we hear a identifier we first check whether it is valid for our app. This means that it must consist of only numbers.\n\nIf the identifier is correctly formatted we decode the transmitted characteristics and then create and add a gem with those characteristics to our screen.","excerpt":"","slug":"ios-offline-walkthrough","type":"basic","title":"iOS Offline Walkthrough"}

iOS Offline Walkthrough


This guide walks you through the Chirp Gem Swap app which is included in our [iOS SDK download](https://admin.chirp.io/sign_up/create_profile). Chirp Gem Swap works completely offline by encoding the information it needs to send within the acoustic identifier. This demo shows how small packages of data can be sent over the audio only using our SDK. [block:image] { "images": [ { "image": [ "https://files.readme.io/7EHmVD4MROOQf9xxDqoj_Screenshot%202016-02-23%2015.23.11.png", "Screenshot 2016-02-23 15.23.11.png", "1115", "804", "#3eb0f5", "" ], "caption": "The iOS SDK download folder layout" } ] } [/block] It's probably easiest if you have that open as we go - if you do not already have a copy you can download or apply to become a Chirp developer [here](https://admin.chirp.io). The first thing we need to do is insert your app key and secret to uniquely identify your app on our systems. Get your key and secret [here](https://admin.chirp.io). Once you have them, insert them in the correct lines of ViewController.m [block:image] { "images": [ { "image": [ "https://files.readme.io/g5X9ybbhQvecokMBcQzY_Screenshot%202016-07-01%2009.54.36.png", "Screenshot 2016-07-01 09.54.36.png", "1152", "242", "#d4774f", "" ], "caption": "Replace your app key and secret at the top of the ViewController.m source file." } ] } [/block] At this point, you should be able to build and run the app in the simulator or attached device by pressing `⌘R` [block:image] { "images": [ { "image": [ "https://files.readme.io/CWMtX6fPSm6pBXP6oASC_Simulator%20Screen%20Shot%2023%20Feb%202016,%2015.26.23.png", "Simulator Screen Shot 23 Feb 2016, 15.26.23.png", "310", "552", "#69af80", "" ], "caption": "You should be able to run this simple single-screen app." } ] } [/block] You can run the app on both the simulator and an attached device, or two devices if you have them. This will allow you to chirp messages between the two apps: [block:image] { "images": [ { "image": [ "https://files.readme.io/EG0lC48hQ0qJe9pqTQQq_Desktop.png", "Desktop.png", "1024", "764", "#67b16c", "" ], "caption": "Chirping gems between two apps." } ] } [/block] [block:api-header] { "type": "basic", "title": "How it works" } [/block] # Sending the gem Gem Swap encodes the position, rotation and colour of each gem in the acoustic identifier that is broadcast through the sender's loudspeaker. Each identifier has 10 digits, so we are able to encode the parameters as follows: ``` [3 characters : X position (percentage)] [3 characters : Y position (percentage)] [1 characters : gem colour] [3 characters : rotation] ``` This takes place inside GemView.m in the `toShortcode` method. [block:image] { "images": [ { "image": [ "https://files.readme.io/XFthuaBHQB2dzcqRH8Be_Screenshot%202016-02-23%2015.42.19.png", "Screenshot 2016-02-23 15.42.19.png", "687", "239", "#39b47a", "" ], "caption": "Our method for encoding the gems characteristics into a identifier", "sizing": "full" } ] } [/block] So a yellow gem (colour 3) at position 0, 100 with 20 degrees rotation would be encoded as ``` 000 100 3 020 ``` and passed to the SDK as: ``` @"0001003020" ``` [block:image] { "images": [ { "image": [ "https://files.readme.io/W11aZD6RfCsdQpmUcX7N_Screenshot%202016-07-01%2009.56.16.png", "Screenshot 2016-07-01 09.56.16.png", "1162", "548", "#2fbd9d", "" ], "caption": "Chirping our identifier", "sizing": "full" } ] } [/block] # Receiving the message Receiving the message is just as simple. We use the `setChirpHeardBlock:` completion handler to parse any chirps that we hear and handle any errors that occur during transmission. [block:image] { "images": [ { "image": [ "https://files.readme.io/3aSL0e9FRjS33ejPJsat_Screenshot%202016-07-01%2009.59.24.png", "Screenshot 2016-07-01 09.59.24.png", "1131", "746", "#2dba99", "" ], "sizing": "full" } ] } [/block] As soon as we hear a identifier we first check whether it is valid for our app. This means that it must consist of only numbers. If the identifier is correctly formatted we decode the transmitted characteristics and then create and add a gem with those characteristics to our screen.