PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] How to get server to direct application to perform function?

 July 12, 2022     ios, message     No comments   

Issue

I am creating app which, among other things, allows users to send messages to each other. I have the messages stored locally in an sqlite database (constructed with FMDB) and it works as intended. However, I am running into a bit of an issue with figuring out how to send the messages between users. What I would like to do is to create momentary objects of the texts in my main database (parse-server) containing the sender's ID, the receiver's ID, and the actual message. This itself is not difficult. What is challenging is figuring out how to allow the receiver's app to recognize when a message has been sent to them and then load that message. I can very easily perform the loading of the message in the viewDidLoad():

func fetchNewestMessageQuery(){
    //pull the message
    tabelView.reloadData() //reload the tableView's data to 
    //populate it with the newest message
}

override func viewDidLoad() {
    super.viewDidLoad()
    fetchNewestMessageQuery()
    //save the new message to the SQLite database
}

This, however, means that the user only ever gets the message when they open the page. How do I basically call my fetchNewestMessageQuery() at any time the database creates a new message object to then send a notice to the app (which may not even be open on the user's phone) to run the query (which is the way basically all message apps work)? I have always been used to only running actions/functions on predictable events in XCode... viewDidLoad(), viewDidAppear(), UIButton presses, etc... and have no idea where to start on functions running without prompt from the app itself.


Solution

You can use silent push notifications where the content-available parameter is sent, and it will be delivered even if the user has disabled push notifications for your app (alerts, really). Your app will even be woken up if it's not already running, and it will be given 30 seconds to process the notification (as long as the user didn't force quit the app).

However, they must have Background App Refresh (requires iOS 7+) enabled for your app. The good news is Background App Refresh will be on by default.

See Configuring a Silent Notification.

You'll need to setup a server to send push notifications.

Alternatively, establish an outgoing network connection of your own to your server, which is basically what iOS does to the Apple Push Notification service.



Answered By - Marcus Adams
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing