Update app data from server (Swift) - php

I need some help with refreshing data. I have an app in Swift 2.0 and I want to the server send an action and execute a method in the app. I already try with push notification and It works greate but if the user disable the notification the method still execute? and according my knowledge this method is only execute when you press the notification. What is the best way to acomplish this?
I am trying to avoid that the app constantly request data from the server.
My server is in PHP.
Thanks!

I think you can use protocols/delegates.
Delegates are good ways to be notified only when needed and and alternative to notifications.
Go check for more here :
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html

With this scenario I think we have these locations to request for updates:
At appDelegate, overriding applicationDidBecomeActive, called when the app becomes active in foreground.
In the view didAppear from the main view from our app (the first view that appears when we open our app).
Both options make more requests to the server than they should, but maybe the 1st is the least costly because is called just when app becomes active, and this is a good moment to check for updates.

Related

Silent authentication via PHP when making API-call

First time posting, long time reading.
I want to perform a silent authentication against Azure AD but I can't seem to get it to work.
Please find image below which outlines steps and overall solution approach.
This is the current approach I have set up and it is working quite well:
User logs in and is authenticated against a SaaS solution via Azure AD.
On the front page within the SaaS solution, user clicks on a widget which opens up a modal window.
Ajax call (POST) (bootstrap-table) is made which calls a php-script from another domain.
PHP script receives ajax request (CORS settings are ok). Here is where I would like the script to perform a silent user authentication against Azure AD and return user's email. It should not in any way display any login-screens or account selection screens. If the authentication fails it should just exit... perhaps with a error message.
Once authenticated, php-script performs API call(s)
On successfull call, JSON data is returned
And JSON returned from PHP-script is displayed on front page (bootstrap-table).
I've been trying with various examples/libraries (thephpleague/oauth2-client, magium/active-directory, ...) and I'm able to authenticate fine via Azure AD App but there is always a login-screen present or select account screen is displayed.
The reason for this approach is that I believe CORS are not secure or perhaps should not be used as a security measure. And also, because some browser does not seem to return Origin I am experiencing some issues...
Now, I'm more of a hobby-developer and perhaps this is in no way possible to achieve but I would like to believe it is and would appreciate any tips/hints on how to perform this silent activity/authentication.
Thank you!

sending automatic push notification from mysql to android mobile

I have a database that contains some data and i want to get notified automatically on my mobile app if any value in the database is changed without having to check the database every certain time,i have tried many methods and viewed several tutorials but it leads me no where,any help ??
This is not going to be possible with only database. You need to write down an RESTful API which your app needs to poll to look for changes.
Ideal way of doing it is using GSM to push notify your app when ever you change something in your app. This will again require PHP/ASP/NodeJS etc... There must be some way you are updating your database? This should go exactly there.

Sending data through php page from android form

I am helping one of my friend in his android app assignment. Here is the problem statement given in his android assignment.
Statement:- There should be proper implementation of POST method with queue to accommodate the data request even when device is in offline mode and execute data sync request from queue as soon as device is online again.
How this task could be done. Correct me if I am wrong, I am thinking that this requires to be done using SyncAdapter. If I am correct and if it has any other way then suggest the same with a tutorial link for implementation.
Yes, indeed you need to use SyncAdapter. Read more here.
Logically, you need to have a message queue, where you push new messages based on user events and possibly other events as well and you need to pop the messages from there and pass to SyncAdapter.

delay websocket updates and show the message later on?

I have an app where basically players challenge each other. At some point their challenge completes and I need to provide them (both of them - there are two players) with an update message, like 'Hey, you won and got 100500 points'. And vice versa - "Hey You looose"
I use websockets and pusher api to tackle the live updates, this works perfectly when player is "online". But what if they are not? The way to go for me looks like I can still handle the event with pusher and instead just displaying the message, I can store it to db to table challenge_notifications with fields messages and seen = 0. it's ok, but what would be the best way then to show this to the player when he comes online next time? I don't want to have ajax request on every page load checking to see if there are any unseen notifications for the user.
I probably somehow need to fetch all pending notifications only once, when they get online?
I use Laravel 5 for my backend.
There was a recent post on the Pusher blog about how to detect if a user is online or not using the Pusher HTTP API: Enabling Smart Notifications with Pusher and SendGrid.
The example uses SendGrid, but you could instead store the update to a database, send them a Push Notification, an SMS etc.
what would be the best way then to show this to the player when he comes online next time?
I guess there are two forms of "coming online":
The user is no longer on the site and has to navigate to the site. In that case as the page loads you can query the DB and serve them up any missed notifications directly (this would seem the easiest solution). Or, if it fits your app architecture, make a single AJAX request when the page loads to get any missed notifications.
If the user has gone offline due to them being mobile or having a bad network connection. In that case you can bind to the connected event using pusher.connection.bind('connected', function() {}); and then make a query to see if they've missed any notifications.
In summary: it would seem that querying the DB for any missed notifications upon normal page render (on the server) would be the simplest solution and wouldn't required much resource usage. But there are alternative mechanisms of delivering a notifications (email, SMS) if they're not online.

how to implement facebook like notification?

I am trying to implement a Facebook-like live notifications system to notify users whenever someone adds them as friend, like their post or posts replies to their comments.
All the database and PHP part is done, but I can't figure out how to implement it like Facebook has.
Whenever someone likes/comments on your post in Facebook the light blue box appears at the bottom left corner of the screen. This happens as soon as someone hits like button or posts comment in Facebook. I would like to know what I should do to implement this.
Using YUI or any JavaScript framework I can query a database table after n seconds to check for notifications. This method is too heavy.
I was wondering if there is any server side mod or scripting can be done so that whenever there is new notification entry in my database table the server will tell that particular client. That way unnecessary request calls from client to server will be avoided completely and system can work efficiently for website with more than 50,000 users online at a time.
How can I achieve this?
You should look into COMET techniques, such as forever frame (tutorial) and long polling. That allows you to have a form of a server->client push communication.
I am really surprised nobody has mentioned PubNub and Pusher
These two (competitors) are building infrastructure which allows for realtime notifications, just like Facebook.
Facebook notification
You basically set a request up, like callng the service that asks your server/db for the notifications of that user. You may do a while loop that retries if theres no notification (maybe Thread.Sleep in between searches). Your js request will timeout, then you can call the function again in timeout. This means long polling afaik
The only way to do it is to have some sort of mechanism (e.g. Javascript) to repeatedly poll the server for updates. Doing server pushes to web browsers isn't possible.

Categories