0

I'm working on an app that uses iBeacon to survey customers who purchased a product. iBeacons are used to send push notifications asking them to rate the service. The problem is that I want to make sure that only customers who purchased something get notified.

Can I make a call to my backend and check whether that customer is eligible for the survey before issuing the notification? I figured this should go under didExitRegion but would it work when the app is not running in background?

hsnpn
  • 27
  • 4

2 Answers2

1

Yes, you can make web service calls in beacon callbacks. The main problem is that if your app is in the background, it is only given 5 seconds of execution time before it is suspended. Even if you make your web service call very fast, if the network is slow, the app might never get the response.

The solution to this problem is to extend background running time. You can see a tutorial on how to do that here. While the tutorial applies to extending time for ranging purposes, the same technique is useful for web service calls, too.

davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • My app closed but when enterRegion like u said I have 5 sec in 1 sec i get my data , then I tried to present local notification but it does not worked when the app close ? why ? I thought I have 5 sec ? – Omarj Oct 08 '15 at 08:53
  • Presenting a local notification from the background certainly works. If you are not seeing this happen, you should post your code so we can help further. This should be as new question (you can link to it from here) since it is a different issue. – davidgyoung Oct 08 '15 at 12:17
  • My question was for a scenario where the app is not running in the background. I don't want to send notifications to customers who just visited the store and did not purchase a product. Is that even possible? – hsnpn Oct 09 '15 at 03:48
  • I used you method to extend the background running time and after many tries it finally worked! Great article and thank you as always. – hsnpn Oct 09 '15 at 05:10
0

Another solution would be using local notifications. Ones the did exit region event is fired up, you can present local notification. When the user clicks the notification , the application will become active and you can do anything you want. Just remember that if the user opens the notification within 5 second, you need to handle it in didRecieveLocalNotification in app delegate. Any other time just check the local notification flague in viewDidLoadWithOptions in app delegate. Hope it helps a bit.

Yonatan Vainer
  • 453
  • 5
  • 15