简体   繁体   English

iOS-推送通知和后台线程

[英]iOS - Push notifications and background threading

I have a service that allows user to enter the type of events they like, and whenever a new event that fits those criteria is available in my database, I want them to get a notification. 我有一项服务,允许用户输入他们喜欢的事件的类型,并且只要数据库中有符合这些条件的新事件可用,我都希望他们获得通知。

I have been looking around at the best way to handle it and I have found two possible solutions, but I'm not very clear with which one I should use and how. 我一直在寻找处理该问题的最佳方法,并且找到了两种可能的解决方案,但是我不清楚应该使用哪种解决方案以及如何使用。

First, a solution that looked great was the didReceiveRemoteNotification method and the usage of remote silent notifications to tell the app that new content was available. 首先,一个看起来不错的解决方案是didReceiveRemoteNotification方法和使用远程静默通知来告诉应用程序新内容可用。 But my questions remains: how can I send this remote notification to the user if I don't know which criteria he has. 但是我的问题仍然存在:如果我不知道他有什么标准,该如何将远程通知发送给用户。 I mean, how can I send this notification using PHP? 我的意思是,如何使用PHP发送此通知? I'm a bit lost here. 我在这里迷路了。

So I found another possible solution that does look a lot like a hack ( iPhone - Backgrounding to poll for events ), to be able to make your app execute a method every XX minutes while it is in background. 因此,我发现了另一种可能看起来确实很像黑客的解决方案( iPhone-后台轮询事件 ),能够使您的应用在后台每隔XX分钟执行一次方法。 This would be way more battery consuming and I'm not even sure it would be accepted by Apple, but at least it is clear as to how it works: the app downloads data from a link with the parameters that fit the special criteria, and if there is new data, it sends a notification. 这会消耗更多的电池,而且我什至不能确定它是否会被Apple接受,但是至少它的工作方式很明确:该应用程序从具有符合特殊条件的参数的链接下载数据,并且如果有新数据,它将发送通知。

How could I combine both these methods? 如何将这两种方法结合起来?

EDIT 编辑

I think the main issue on my side is that I don't understand how I could check a certain PHP file whenever new data is added into mysql and make sure that it fits the criteria of the user and then send the notification. 我认为主要的问题是我不了解如何在将新数据添加到mysql中时检查某个PHP文件,并确保它符合用户的条件,然后发送通知。 That is the part that I don't understand in the backend PHP usage. 这是后端PHP使用中我不理解的部分。

Your flow should be like this - 您的流程应如下所示-

Mobile -> BackendServer(PHP) -> APNS server -> Notifications->Back on device. 移动-> BackendServer(PHP)-> APNS服务器->通知->返回设备。

User will submit her/his criteria to server then server will process on that and send request to APNS server. 用户将自己的条件提交给服务器,然后服务器将对该条件进行处理并将请求发送到APNS服务器。

The APNS server will send remote notification on her/his device based on criteria requested. APNS服务器将根据请求的标准在其设备上发送远程通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM