Friend request real time notification to recipient device - objective-c

I want to notify a user if any other user wants to be friend with him. The only ways I can currently think of is notify through push notifications or recipients device will keep polling server for new information at certain frequency or device will check for new information only when it launches.
I have some problems with Push Notifications method to send requests
If device is offline only last notification will get processed
If app is not running, push notification will get delivered in Notifications and I don't know how can I extract information from there to my app.
Also, if device keeps polling for new information number of API calls will be very high which is not cost effective and alternately if device asks for new information only at start up launch it will not get real time updates.
Is there any way I can send information to device as soon as information is available?.
Any suggestions will be appreciated

Have you taken a look at Urban Airship?
They have a great framework set up for queueing and receiving push notifications, even when your app is offline. You can either queue the notification from the app itself or from your server hosting your account data. They also have the ability to compose and push rich content notifications.
The basic account for small apps gets 1 million free push notifications per month. Everything beyond that is fractions of a penny.
Hope this helps, Cheers!

Notifications is one such thing which can drain down battery if one takes polling route, thats one of the reasons Apple developed Push Notifications. I would recommend try to use Apple Push notification as much as possible as it would have been optimized to hell. If you have different flows for when the app is active & for when the app is not active (reg. notifications) you can do it like so -
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if(application.applicationState == UIApplicationStateActive) {
// app active.
}
else {
// app not active
}
}
But if in any case Apples Technology does not suite ones needs one could always use third party services. In this case there are a few that can really help you.
Pusher has an Objective-C library and a REST API (along with a number of libraries) that would let you push realtime updates from your server into an iOS application.
OpenPush is another such service. Also check this link, here's a compiled list of realtime technologies in which I'm sure you'll also find technologies that meet your requirements.
All of these are better than polling.

Is there any way I can send information to device as soon as information is available?. Any suggestions will be appreciated
user1 wants to add user2 as friend.
from device, post information to server, in your webscript, process the friend request of user1 to user2 (insert/update information to database etc), when done. send the notification to user2. this will work if the device is offline, user2 will have real time update, if the app is running. you can run scheduled request that will check new notifications. say every 2 minutes, a method in your app runs. but thats not a very good idea. A reload button inside the app to check notification is better.

What you would normally do is to use the push request as a means of informing your app that new data is available. The user clicks on the push notification - the app is opened with the
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
you register that there was push, query your server and the server let's your app know that this list of new friend requests are there.
You can't really do the queuing of messages on the device - and you don't need to. It's much easier to just store the info on your server until the app queries it.

Related

Notifications for inactive users

I’m implementing a solution that will notify users in a scenario very similar to a chat.
I’ll be using SignalR and Azure Notifications Hub for the job.
There are two scenarios that I need to address:
Notifying users that are currently connected and using my app - either web or mobile
Notifying users who are NOT currently using the app
I think SignalR will work just fine for the first scenario which is fairly easy.
My question is handling the second scenario which will require Azure Notifications Hub.
In a typical chat app, though it’s not real-time, there’s little delay before an inactive user receives a notification for a new message he receives.
How do I “trigger” a process that will send a notification through Azure Notifications Hub?
I can think of two ways to handle this:
Figure out a way to keep a list of users who currently have an active connection to my app. These users can be notified through SignalR. So after each new message, I could trigger a notification process that will use Azure Notifications Hub for users who are NOT in the active users list i.e. those who are NOT actively connected to my app.
Another approach would be to assume no one is connected. I could create an Azure Functions app that runs every minute to check on messages that are NOT opened. It would then compile a list of users who need to be notified and call Azure Notifications Hub process to notify them.
I don’t want to reinvent the wheel and want to tap into the experience of those who’ve already implemented a solution like this.
I’m currently leaning towards the second approach. I’d appreciate your suggestions, especially on approaches that I haven’t thought of. Thanks!

Can you apply time restrictions for ibeacon notifications when exiting a region?

I have implemented iBeacon into an app so that it will wake the app briefly from a suspended or killed state. A push notification is sent which would prompt the user to open the app if they wish to.
The problem is, when a user exits then enters a region again another notification is sent. In a shopping mall for example a user could walk past many beacons (enter and exit regions). What they probably will not want is lots of notifications annoying them.
Is there a way that you can control or restrict the number of notifications a user gets? For example time restrictions? Once a notification has been received then a user would not get another one for 15 mins or 30 mins etc?
There must be a solution as i am sure Apple would not want users to get lots of notifications that users dont want.
There are no built-in tools to iOS SDKs to prevent multiple notifications from being sent in a specific time period. But you are correct that this is a very common problem. The solution is to just add a little bit of programming logic.
Here is a typical approach:
Each time you send a notification, record a timestamp of when you sent it. Store this in the phone's persistent storage, so even if a user restarts the app or reboots the phone you will have a record of when the last notification was sent.
UserDefaults.standard.set(Date().timeIntervalSince1970,
forKey: "lastNotificationSentTime")
Before you send a notification, check to see when the last time you sent one was. If it was too recent, suppress sending a new notification.
let lastNotificationTime = UserDefaults.standard.value(forKey: "last") as? Double ?? 0.0
if Date().timeIntervalSince1970 - lastNotificationTime < 60.0 {
print("Not sending notification because I just sent one in the last 60 seconds.")
}
else {
// TODO: Send notification here
}

Strategy for notification checking

Is there a recommended strategy for checking of notifications within my AngularJS app?
By 'notification' I'm talking about message alerts that are to be displayed to a user when they're logged into the application.
My plan is to notify the user of unread notifications in the app's NavBar as shown below:
My app communicates with my restFul API (written using Node.js, express, MongoDB), so I anticipate that new notification will be written to a MongoDB collection with details the user the notification is intended for.
What I'm unsure about is how the AngularJS application will check for notifications once a user is logged on. I could call my API for unread notifications every time the user navigates from one path to another but that seems simplistic and it wouldn't work if a new notification occurs whilst a user is viewing a page.
Another way would be some sort of timer system that checked, say, every 30 seconds. But this would results in unnecessary polling of my API when there aren't any new notification for a user.
So, wondering if there is a recommended strategy. Thanks for your help.
Polling is a solution but it is very inefficient. The solution to your problem are websockets. Websockets is a technology that provides a full-duplex bidirectional communication between your clients and your server. So you can send messages from your server to your connected clients. Your server maintains an array of connected clients and you just have to know which ID you need to send a message to it.
For your stack, the best solution I have came to is Socket.io http://socket.io
It also have cool features. For example, you can "observe" models, so if a model change in your database, for example an update to a user profile is made, you can trigger an event and automagically send a message to your client. This client get and handles the notification and do something, like put a badge on your alerts icon.
Hope this is useful for you.

IOS UILocalNotifications live after my app has been deleted...how to deal with these notifications?

I was wondering how to deal with UILocalNotifications that were created using my app but the app then got deleted.
Lets say that after creating a few notifications, the user decides to delete the app, but i've noticed that even though the app is deleted the notifications lived and they still fire in the correct time, but this doesn't make sense to me since the app is not existant in the phone anymore.
I understand how this is possible, but i would like to know if there a way to delete such notifications when the user decides to get rid of my app?
And does this happen as well if the app is being updated?
Thanks.
Another way is to use APNS (remote notifications) instead of local notifications.
This way, once your App was removed, pushed notifications will not get to the device anymore , nor to the user's attention.
At this stage you can be aware of the App's removal (using APNS feedback service) and cease your sending mechanism for that user (his push token..)

How does push work on ipod touch with respect to auth credentials?

I installed this instant messenger program called IM+ that keeps your accounts online even when you exit the application (you know... touch: only one app at a time) it accepts push deliveries to report you have a message.
I am kind of puzzled on how they can keep me logged in and send me a push notification that someone is messaging me. I noted the same happens for mail. If I receive a mail, even if I don't have mail open, a badge appears near the icon.
My main concern is the password. How does push work? does it mean that apple or the company behind IM+ stores my email and instant messenger passwords to keep me logged in and push me a notification when I have something new ?
Edit: ok... the tumbleweed is a bit too much for such a question.
Read this to understand how it works: Apple Push Notification Service