IOS : Push notification on user defined time duration - ios7

My app should get push notification on user defined time duration (like on each Monday 11 AM).
So for that App have to check for new updates on server (on background) on user defined date and time, App might not be running at this time, but it still has to check for new updates on server. If any update found, server will send push notification for the same.
How can I implement time based background process?
Thanks!

Why don't let the server do all that? I mean, you will have to do a post with the selected date by the user from the app, and the server at the selected time will send a push notification to that particular user (you know what user it is by his token id). Amazon Web Services works like that for example.

Related

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
}

How do I send data to server when device power on in iOS using Objective C

Now I am developed an application that have to send current location to server for trigger a notification to users when he/she approached the shop.And the problem is when user start device at the first time my app doesn't run thus it can't send the current location to server. How do I do this task?
What I want to know is how to call some function in the app when device started.
Thank you very much.

send notification to a particular user with notification hub - Azure and GCM

I am a software developer in Xamarin - Android, I want to create notification messages. For this purpose I use Azure notification hub, combined with Google's service - Google Cloud Messaging (GCM).
My problem comes when I want to send notification to a particular user. I realized that I need to use the "TAGS" When I compose a new user to the system (Uniqe TAG)
Indeed, it works great, but when the user logged off his account, and then connect to another one (with another TAGS) - the TAGS of his old account are kept in a certain time, and he continues to receive personal messages from the previous account!!!!
Does anyone know what can be done about it?
thank you very much
This is actually an issue a lot of people/apps have on iOS and Android.
What you should do is:
Register your app at your Azure Notification Hub (ANH) on first start and reregister at every app start, to keep registration in sync
If a user logs in, update the registration with an additional tag for this user (e.g. "user:XY")
Sending notifications to that user tag will of course result in notifications on all devices the user is logged in on
If a user logs out, update the registration without the user tag (omit the user tag, so the registration doesn't have user tag anymore afterwards)
The registration will be updated immediately on ANH and sending notifications to the user (tag) will not result in notifications on that specific client
If the user can logout on your app without internet connection, you won't be able to update the registration of course and you will still have the problem of getting notifications for a logged out user. But as soon as another user logs in, the registration should get updated with the new user tag and everything should be fine again...
What you shouldn't do:
"Developers should never unregister the client app as a mechanism for logout or for switching between users..."

How to send push notification according to dateTime which is stored in database?

I need conceptual help.
I've a web application in asp.net MVC that create schedule (just like reminder application) according to date time and store this information in database. Now I would like to send message to user on that date and time(not manually.
Users means mobile phone app (My created app) user, phone will receive push. user not concerned about my web application it a control panel.
Usually i send push notification manually to user device by running a script from web application, It can send instant notification but i need to send it according to time schedule automatically.
How can i do this???
You need a task scheduling library for web application. define a task and run task in background for sending notification in desired intervals. For more info read this post by Scot Hanselman.
Here is top 20 NuGet packages for tasks.

Friend request real time notification to recipient device

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.