Free up to 1MM monthly messages. No credit card required.
Ever since the Apple Watch was announced, I’ve thought it was an interesting device for sending and receiving quick bites of information, which makes it a perfect match for PubNub technology. In this article, I’d like to share one of my ideas, a real-time voting app using the PubNub Mac, iOS, and the beta watchOS SDKs.
The real-time voting app lets the owner of the server create short polls to be shared with other users through an app. This would be perfect for a classroom setting.
The project has a simple three-component architecture:
Each component above communicates using the PubNub SDK libraries for each platform: Mac, iOS, and watchOS. The workspace is configured to use static libraries to demonstrate separate binaries for each component.
Note: It is strongly recommended not to use PubNub client directly on the Apple Watch and to organize project architecture in a way where paired device will be the core for data retrieval. Apple Watch in it’s default configuration will turn off screen after 15 seconds of no interaction – this is how Apple tell us not to run any long-running tasks (like subscribe from PubNub client) on Apple Watch.
The poll host allows the user to publish a new poll with a question and up to 5 possible responses. The app itself shows statistics real-time in a table. Statistics for attendees and observers is aggregated and sent every half second.
If the previous poll wasn’t completed properly, after restart the app will pull out information about it and the last statistic which it generated.
Note: If the host is offline, votes from attendees won’t be saved (saved only through aggregated updates). Make sure you start the host app first.
The main real time iOS app allows the conference attendees to give their vote for one of options provided by the poll host. As soon as the publish operation is completed, the user will be presented with bar chart which will be updated every time the host sends out aggregated statistics information (currently set to every 500 ms).
As with the real-time host app, the attendee’s iOS app uses searches through the previous session to pull out poll information even if the poll was started before user the installed the app. The latest statistic will be pulled out as well.
Note: This is a simplified real-time polling system which doesn’t track whether the conference attendee already voted or not. In a real system you would need to prevent ballot stuffing.
The app (with proper PubNub account and provisioning configuration) provides push notifications for each time when new poll announced or completed.
This is an Apple Watch Extension which allows the user to observe the polling process in real time using bar chart on the screen. As with the host and attendee’s apps, the watch extension is able to catch up on previously started votes and receive latest aggregated statistics.
Let’s compile and run the sample apps. The source code is available on this github repo.
To be able to deploy on device and launch the host app, you need to prepare an XCode workspace by running the CocoaPod command from the repository root folder in your terminal:
After everything will be completed, open the PubNubPoll.xcworkspace workspace and use configured targets for deployment and host launching.
To run the Mac app, choose the target as Mac then run it:
You can set a poll in the Mac app and press the Start poll button to start it.
To see the current stats on your watch, choose the target as watch and run:
To vote, chose the Xcode target as iPhone and run it:
When you vote, the watch will update with the current stats:
The PubNub API on the Apple Watch is the same as iOS, only the compilation is different. This SDK is not beta, however there is no Xcode support for watchOS automated testing. We can support watchOS but we can’t test against it. We have filed a ticket with Apple and will update the SDK when Xcode changes. If you have any questions or want some new features, please let us know.
A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.
Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...
Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.