real time messaging for multi player game on ios - ios

Building a multi player iOS game where players compete one against the other. Nature of the game is synchronous. Basically, players either invite each other through facebook, email, etc and then start playing.
We debate what is the best strategy for facilitating the real time communication between players (sending events, etc). Coming from web development, we used comet and long polling which worked great. However, it's not clear what's the best way to achieve that on iOS.
Seems like APN (Apple Push Notifications) is not suitable in our case for two reasons: the delay can be pretty significant, up to few seconds, as far as we understand. Also, using APN requires the user to authorize notifications. If the user doesn't authorize this then it won't be possible to play the game.
Also, we understand Apple's Game Kit (Game Center) can be of value in our case however it's not clear how it interacts with invites through facebook etc. Also, not clear if we need to get into bed with Apple's Game Center and how it'll affect the user experience.
Any guidance on this matter as well as other options that you might think of would be greatly appreciated.
Thanks for your help.

Before you read the rest, a disclaimer: I work for Realtime.co but I do believe I can help here so I'm not trying to "pitch a sale".
If you need to have real time updates, you can check out Realtime (www.realtime.co). It's basically a set of tools for developers to use real time technologies on their projects. It uses websockets but does fallback to whatever the user's browser supports (such as long polling, for example) if you are using a browser (which is not your case, but it's always good to know).
Behind Realtime you have a one-to-one/one-to-many/many-to-many messaging system that will transport your messages to and from your users.
There's a iOS API too which you can use in your project. You can download it here: http://www.xrtml.org/downloads_62.html#ios and check the documentation here: http://docs.xrtml.org/getting_started/hello_message.html#ios.
There's also a plus which is the fact that the Realtime framework is actually cross-platform. This means that you can even have your iOS players to communicate with players using Android, Windows Phone, HTML5, Flash, etc. if you decide on expanding your game to other platforms.
I hope that helps!

I'll just provide some insights on the question.
APN should never be used for synchro communication as for iOS at least, you'll never have both way communication (basically the Apple APN servers are pushing an information to the device).
You should probably play with C sockets in order to open a tunnel (depends if your game is real time or not).
Using the Apple Framework GameKit is great! But might take some time to understand all the functionnalities.

Check out Gree
https://developer.gree.net/en/
Parse:
https://www.parse.com/
Sparrow:
http://gamua.com/sparrow/
There are a few things that your talking about, there is the joining/starting of a game, and then the communication between the players. They are not necessarily related.
You can use game-center and at the same time another framework for facebook, they are not mutually exclusive (but it would be more work.)

Related

How do social networking apps update their UI in real-time?

I was wondering how social networking apps, such as Twitter, Facebook and WhatsApp update their user interface in real-time when another user interacts with the user of the app. To use the best example I can think of: when you have a chat window open in WhatsApp, the UI updates automatically (without any user actions required) when the user you're chatting with interacts with you. Messages appear on your screen without refreshing and the "last seen" status at the top of the screen updates automatically when your chat partner either goes offline or comes back online. I can think of two ways to achieve this:
Remote push notifications: this approach strikes me as the 'cleanest' way to do this, but it's probably also the riskiest way. Using silent notifications (content-available) to pass data to another device at the moment a user does something, would probably save you a lot of HTTP requests and therefore would make your app consume a lot less data and CPU usage. The risk of this approach is that a user can easily disable ALL push notifications to save battery power (including silent notifications) and then your app wouldn't be able to get notified on events remotely.
Local UI refreshing: This approach is obviously the safest, but I think it's really 'nasty' and eventually everyone would feel the downside of it. Constantly refreshing the UI and re-retrieving data from the database to make sure the latest messages and statuses are displayed to the user would be safe in the way that your app doesn't have to rely on the device's battery and background mode settings, but the downside is that this will make your app consume a lot of data and battery power, which would be bad for the user's data plan and his device. I also don't think Apple would approve of an app that's consuming so much data and power.
I've just implemented a chat function into my own app, and I want to enable the same real-time UI updating that WhatsApp uses. What would be the best way to do this? Should I use one of the two methods above or can someone think of another way to do this? By the way, I'm a relatively new programmer who just recently learned how to develop iOS apps (Swift). I'm very far from being a pro, so please go easy on the explanations and work method capabilities. Thanks!
The chat apps make use of WebSockets to create a constant connection with the client and a backend server.
This article on Appcoda can help you start learning about Socket.io. It answers your questions and also helps you to create a demo app.

Is there inter-app communication when apps start in iOS?

I am relatively new to iOS app development and I'm just trying to figure out some things that, to me, are more abstract. How do apps know when other apps start? The closest example I can think of to what I'm trying to ask is when music is playing in the background and you open another app that has sound and the music stops. Is that the new app taking authority or is there inter app communication? If there is communication how does that communication work? Like is it a message that could be accessed or what?
Sorry if that didn't make much sense, I tried to elaborate the best I could. I couldn't find anything on this on apple's developer website. Thanks in advance!
There is no inter-app communication. Each app is living in its own world, and as far as your app is concerned, it's the only app on the phone. The way communication happens is that an app talks to the system, and the system talks to your app. The way the system sends messages to your app is usually in the delegate of the framework you're working with. In your example, opening your app to play audio will send a message to the system, and the system will tell the other app to stop audio playback. That other app has no idea it was your app that initiated the stop. Another example is the AppDelegate. The app delegate will send your app messages such as application:didFinishLaunchingWithOptions:, which in this method is where you do custom initialization of the app or applicationWillResignActive: which is normally sent when the user presses the home button or receives a phone call, so here you might want to save your game, etc.
In fact the iOS system is quite complicated, much to complicated to be explained in detail here so I highly suggest reading the Apple Developer Documentation, some of it can be a little dry, but they do their best to be coherent with even absolute beginners.

Block and/or Silence incoming notifications

My company is currently contracted to write a meditation app. While we have the app 90+% done the client has come up with a new requirement they would like implemented. Thankfully we have not agreed to the new requirement as we were not sure if it is possible or not.
They have seen in other apps (games were the only examples they were able to provide) where notifications (i.e. incoming email) did not appear and did not play a sound.
I have searched the old google god and have not been able to come up with an answer for my higher ups. Is there a way to accomplish this or is this something that is only available for games?
Thanks.
I don't think it is possible. The only thing that I would guess is that you would turn on do not disturb pragmatically. But there is no code for that, that i know of.

I want to build a massive social async game mode into my iOS game, is there an iOS API for that?

I’m building my 2nd game now and I’m wondering if there’s an iOS API to help me out with building a social async game. I’ve used GameCenter before (for leaderboards) but I don’t think GameCenter is something I can use for this.
Are there any open source components I can use instead? Something like the Facebook SDK?
Would I need to have the game run on a server?
You could actually use GameCenter for some of the things you wish to build. For instance, there’s a built-in mechanism for matchmaking and turn based style games. You can have a look at GKTurnBasedMatch for more information.
However, GameCenter does have its limitations. There’s a great blog post by Andrew Plotkin that describes his experience with building a GameCenter based turn-based game. In short, using GameCenter is a bit convulted, one of the players in the match needs to constantly maintain the game state (since it’s all client based) and there is no possible way for both players to act simultaneously. Also, there are issues with players logging out of games (Apple doesn’t provide a mechanism for forfeiting the game or skipping someone’s turn).
You could always take the long road and implement the game using your own server. You would need to build several mechanisms like registration, matchmaking, push notification integration, storage and of course client to server communications.
Another option to consider would be to use Nextpeer’s SDK. They provide a complete solution for games that wish to incorporate a “play with friends” feature and it’s free. They take care of the matchmaking, push notifications and all server-side logic. The game itself just needs to implement some simple methods like starting a game, reporting score and ending a game. It’s pretty easy, they have a simple screencast here that shows how to do it.

Transfer data over wifi without a database

I want to get to know how I can transfer data easily between 2 iPhones, over wifi. I would like to know if I could do that without having a server or database, but within an app (so without using email).
Game Kit has support for Peer-to-Peer-Connectivity and is, despite the name, not only usable for games:
The GKSession class allows your application to create and manage an
ad-hoc Bluetooth or local wireless network, as shown in Figure 1.
Copies of your application running on multiple devices can discover
each other and exchange information, providing a simple and powerful
way to create multiplayer games on iOS. Further, sessions offer all
applications an exciting mechanism to allow users to collaborate with
each other.
You can also check out Bonjour API from Apple. I am not sure if you need a static IP for it to work or it can just work over wifi. Just trying to give a pointer.
Based on your exact usecase, it can work well.
Check it out here, Game center is also there.
http://developer.apple.com/technologies/ios/networking.html

Resources