Hype is a SDK for cross-platform peer-to-peer communication with mesh networking. Hype works even without Internet access, connecting devices via other communication channels such as Bluetooth, Wi-Fi direct, and Infrastructural Wi-Fi.
The Hype SDK has been designed by Hype Labs. It is currently in private Beta for iOS and Android.
You can start using Hype today, join the beta by subscribing on our website.
This project consists of a chat app sketch written to illustrate an integration between two technology's, Hype framework and Twilio iOS SDK. This demo allows users to communicate with a public chat room even if they don't have internet access.
Most of Hype documentation is inline with the code, and further information can be found on the Hype Labs official documentation site.
The first thing you need is the Hype SDK binary. Subscribe for the Beta program at the Hype Labs website and follow the instructions from your inbox. You'll need your subscription to be activated before proceeding.
Hype is really easy to configure! Open the project with Xcode and drag the binary into the project in the Project Navigator. Also see Apple's documentation page with details and alternative solutions. Some versions of Xcode require adding the framework to Embedded Binaries in the project's General configurations.
Go to the apps page and create a new app by pressing the Create new app button on the top left. Enter a name for your app and press Submit. The app dialog that appears afterwards yields a 8-digit hexadecimal number, called app identifier. Keep that number for step 3 . App identifiers are a mean of segregating the network, by making sure that different apps do not communicate with each other, even though they are capable of forwarding each other's contents. If your project requires a deeper understanding of how the technology works we recommend reading the Overview page. There you'll find a more detailed analysis of what app identifiers are and what they do, as well as other topics about the Hype framework.
The app identifier must be set in the project's Info.plist file or before starting the Hype services. You'll find your Info.plist in Project Navigator under the Supporting Files group. If you are not sure how to edit your Info.plist, we recommend reading Apple's documentation here for that regard. Add a new top level entry on your Info.plist called com.hypelabs.hype and set its type to Dictionary. Expand the entry by clicking on the arrow on the left and replace the New item text with appIdentifier. Set its type to String and the value to the identifier that you got from step 2. Alternatively, you can set it using the method setAppIdentifier
, before starting the framework's services, with an NSString
value indicating the identifier. The following example illustrates how to do this. The 00000000 identifier is reserved for testing purposes and apps should not be deployed with it. Also, setting the app identifier with setAppIdentifier:
takes precedence over the identifier read from the Info.plist file.
[HYP setAppIdentifier:@"00000000"];
The first thing we need to do is grab all the necessary configuration values from our Twilio account. To set up our back-end for Chat, we will need four pieces of information:
Config Value | Description |
---|---|
Service Instance SID | Like a database for your Chat data - generate one in the console here |
Account SID | Your primary Twilio account identifier - find this in the console here. |
API Key | Used to authenticate - generate one here. |
API Secret | Used to authenticate - just like the above, you'll get one here. |
A Chat application has two pieces - a client (our iOS app) and a server. You can learn more about what the server app does by going through this guide. For now, let's just get a simple server running so we can use it to power our iOS application.
Unzip the app you just downloaded, and follow the instructions of the language you choossen.
To confirm everything is set up correctly, visit http://localhost:8000/chat/ in a web browser. You should be assigned a random username, and be able to enter chat messages in a simple UI that looks like this:
Feel free to open this app up in a few browser windows and chat with yourself! You might also find this browser app useful when testing your iOS app, giving you an easy second screen to send chat messages. Leave this server app running in the Terminal so that your iOS app running in the simulator can talk to it.
Now that our server is set up, let's get the starter iOS app up and running.
The source code in this application is set up to communicate with a server
running at http://localhost:5000
. If you run this project on a device,
it will not be able to access your token server on localhost
.
To test on device, your server will need to be on the public Internet. For this,
you might consider using a solution like ngrok. You would
then update the localhost
URL in the ViewController
with your new public
URL.
Our mobile application manages dependencies via Cocoapods. Once you have Cocoapods installed, download or clone this application project to your machine. To install all the necessary dependencies from Cocoapods, run:
pod install
Open up the project from the Terminal with:
open ChatQuickstart.xcworkspace
Note that you are opening the .xcworkspace
file rather than the xcodeproj
file, like all Cocoapods applications. You will need to open your project this
way every time. You should now be able to press play and run the project in the
simulator. Assuming your PHP backend app is running on http://localhost:8000
,
there should be no further configuration necessary.
Once the app loads in the simulator, you should see a UI like this one:
Start sending yourself a few messages - they should start appearing both in a
UITableView
in the starter app, and in your browser as well if you kept that
window open.
You're all set! From here, you can start building your own application. For guidance on integrating the iOS SDK into your existing project, head over to our install guide. If you'd like to learn more about how Chat works, you might want to dive into our user identity guide, which talks about the relationship between the mobile app and the server.
MIT