I’ve been programming Apple devices now for nearly 10 years and much has changed in that time. For the last few I’ve been concentrating my efforts on iOS (previously iPhone OS) which is the operating system found on iPhones and iPads. Unfortunately, the Mac side has been left behind (although I hope to get back to that under Mavericks).
Over the last few days I’ve been adding push notifications to an app that I’m in the process of developing for a customer. Probably the biggest surprise for me (and perhaps I’m just being naive here) is that you can’t send out a global push to everyone who has your app – you have to send a separate push message to each of your users.
This means having to store a device token centrally for each person who runs your app and then go through each of these tokens as part of the push. Not too much of a problem if you have a few hundred users, but what about when you get into the thousands?
How many people, I wonder, have downloaded the BBC News app and how much server time must it take whenever the BBC want to send out a news flash to them? I shudder at the thought (as must their IT department).
There’s dedicated method in AppDelegate.m that handles the registering of push notifications:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
It appears that this method is called not just when someone first allows your app to receive push messages (via the alert that appears asking for permission) but whenever your app is run. This I find helpful, as I’m using an ASIFormDataRequest to send the device token to a back end server where I check whether or not it exists in my database. If it doesn’t, I add it. If it does I set a most recent accessed date to today.
In my push notification process (based inside a bespoke CMS) I only retrieve device tokens for copies of the app that have “phoned home” in the previous 180 days (that may change). My thinking is by keeping a handle on active users I can avoid sending to people who either no longer use the app, or have removed it from their device. I’m hoping this, in some small way, can reduce the load on the server.
At least until I get as many users as the BBC have got(!)