Apple Push Notification Service with UILocalNotfication + Sync Gateway instead

211 views
Skip to first unread message

CouchbaseLover

unread,
Jun 9, 2014, 6:12:27 AM6/9/14
to mobile-c...@googlegroups.com
"Apple Push Notification Service with UILocalNotfication + Sync Gateway instead"

What do you think about this idea? We thought about this and we can't come up with why it wouldn't work and could actually be a lot better, better performance and better control (not having to manage another server solution etc).

Would be interest in "J.Chris" solution to "APNS" and haven't found any link (searched on the forum and github). Maybe it's similar to what we thought about? :)

Regards CouchbaseLover




Jens Alfke

unread,
Jun 9, 2014, 10:50:39 AM6/9/14
to mobile-c...@googlegroups.com

On Jun 9, 2014, at 3:12 AM, CouchbaseLover <sharess...@gmail.com> wrote:

"Apple Push Notification Service with UILocalNotfication + Sync Gateway instead"
What do you think about this idea?

I don’t know what that would be. Can you describe it in more detail?

—Jens

CouchbaseLover

unread,
Jun 9, 2014, 11:26:45 AM6/9/14
to mobile-c...@googlegroups.com
Yeah sure, il try my best :)
First off, i hope i am not wasting our times if this has already been answered, but this is the closest i got to a similar topic here: https://groups.google.com/forum/#!topic/mobile-couchbase/q0fbOLvKkt8


Example 1.
Ok let's say we expand the way "CouchChat" works and implement Apple's Notifications but without the use of talking to the APNS server. Instead we check the gateway’s _changes feed and use that instead to make a "UILocalNotfication" instead of a "Push Notification" that needs to talk to the APNS server. We create the "UILocalNotification" and populate the message/badge/alert reading the gateway changes? (does not sound right).

Example 2.
We create a new document called "TNotification" that has a type: TNotification and belongs to the Chat Channel, with the properties that makes a UILocalNotfication (message/badge/alert etc). So everyone in the Channel will receive the TNotification document that when received we create a UILocalNotfication something like this.

1
2
3
4
5
6
7
8
- (IBAction)createTNotification:(UIButton *)sender {
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = [CBLJSON dateWithJSONObject: or something
    localNotification.alertBody = TNotfication[message] or something
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = 1;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

Regards

CouchbaseLover

Jeff Kingyens

unread,
Jun 9, 2014, 11:33:55 AM6/9/14
to mobile-c...@googlegroups.com
I don't think this is a good idea. First of all, you would be missing certain functionality. For instance, you can use APN to send a real-time event to your application regardless of the application's state. Even if your application is completely shut down, Apple will invoke your application if the platform receives an APN event with your bundle ID. I am not sure how you would replicate this behavior using the sync gateway + local notifications. You would be at the mercy of background fetches, which you have no control over and might never come (there is no way to set a maximum interval between background fetches). So in this case, how would you have better control? Or even better performance for that matter? APN is designed for performance (battery life) and is in a better position to make decisions to optimize for this because it has a complete view of the user's iOS device and all application requirements.

It seems the right way to do this is to actually use APN to send the signal to an iOS device that a sync is required and then call the couchbase replication methods. You could then add application level logic on top to figure out what changed (or provide this information in a document). I do agree that some extra work is required to set this up and it would be nice if it was some how integrated into the sync gateway. In my case, I already have a server-side solution doing custom authorization (I allow google accounts, facebook, github and a bunch more), so adding additional functionality to understand the user's devices and perform APN pushes is not that big of a deal. However, it would be cool if a user's device tokens were an extension of the sync gateway user model, and you could upload APN SLL certificates and configuration and have the gateway send push notifications to the device.

Jeff

Jens Alfke

unread,
Jun 9, 2014, 11:48:20 AM6/9/14
to mobile-c...@googlegroups.com

On Jun 9, 2014, at 8:26 AM, CouchbaseLover <sharess...@gmail.com> wrote:

Ok let's say we expand the way "CouchChat" works and implement Apple's Notifications but without the use of talking to the APNS server. Instead we check the gateway’s _changes feed and use that instead to make a "UILocalNotfication" instead of a "Push Notification" that needs to talk to the APNS server.

Oh, I see. This will only work while your app is active/visible. The main advantage of push notifications is that they can be delivered even when your app isn’t running. Push notifications also don’t require keeping an open socket to the server, so they’re a lot better for battery life. (They’re triggered from a sideband message over regular GSM, kind of like an invisible SMS message, so they don’t require keeping the faster and more power-hungry 3G/LTE/4G/WiFi radios active.)

—Jens

CouchbaseLover

unread,
Jun 9, 2014, 12:14:52 PM6/9/14
to mobile-c...@googlegroups.com
Couldn't ask for a better reply, and i completely agree with that it's a bit of a hassle to "only" reinvent the wheel all the time. Maybe you should go all CloudKit on this one ;)

CouchbaseLover

unread,
Jun 9, 2014, 12:15:48 PM6/9/14
to mobile-c...@googlegroups.com
Also true! Thanks for the quick response, can't say it enough.

James Nocentini

unread,
Nov 13, 2014, 4:57:13 PM11/13/14
to mobile-c...@googlegroups.com
I'm trying to set up Apple Push Notifications when some user actions are triggered on the app. Here's what I have managed to do so far:
- User logs in and accepts to receive push notifications
- New Profile document is saved with device_token as one property
- Then when a push notification is needed, create a Notification document and save it.

Using follow to get notified of changes and check if the type of the document is "notification". From there I need the list of device tokens but I'm struggling to get them.
Tried using cradle but I can't get save/query views to work. It seems like the sync gateway REST interface doesn't support views?

follow(configuration, function(error, change) {
  if (!error) {
    console.log('got change number ' + change.seq + ': ' + change.id);

    if (change.doc.type == "notification") {
      
      // missing: query a view on the sync gateway
      // to retrieve all the device tokens
      // to send the notification to
      
    }
  }
});

Looking at the push notification robot to fetch those device tokens via a channel but I couldn't find the sync-wrangler node module.
What's the best way to retrieve device tokens in this case?

Thanks

Traun Leyden

unread,
Nov 13, 2014, 5:02:23 PM11/13/14
to mobile-c...@googlegroups.com
You can access views via the admin API now, see:


The non-admin API is coming soon:


Which version of Sync Gateway are you running?


--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/3f089edf-73a9-4efc-ab33-67f224e45c6d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Traun Leyden

unread,
Nov 13, 2014, 5:44:46 PM11/13/14
to mobile-c...@googlegroups.com
Yup, querying couchbase server directly is another option.

What you are trying to do definitely sounds like something you would want to use a view for.  


On Thu, Nov 13, 2014 at 2:42 PM, James Nocentini <james.n...@gmail.com> wrote:
Great thanks
Using Sync Gateway 1.0.3
I will try to go for the option described in the third comment of https://github.com/couchbase/sync_gateway/issues/379
Another option would be to query the view directly to the Couchbase Server with https://github.com/couchbase/couchnode ?

I'm still not sure in which use case to use the sync-wrangler approach with channels instead of view queries https://github.com/couchbaselabs/CouchChat-iOS/blob/push/push-notifications/index.js

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/EBuekY1Vizs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CACSSHCHePvDsrb7H_Us_j3TYoPT%2B9CxcE4jiMajEajW5-CbuAQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.

James Nocentini

unread,
Nov 13, 2014, 5:45:02 PM11/13/14
to mobile-c...@googlegroups.com
Great thanks
Using Sync Gateway 1.0.3
I will try to go for the option described by Jens in the third comment of https://github.com/couchbase/sync_gateway/issues/379
Another option would be to query the view directly to the Couchbase Server with https://github.com/couchbase/couchnode ?

I'm still not sure in which use case to use the sync-wrangler approach with channels instead of view queries https://github.com/couchbaselabs/CouchChat-iOS/blob/push/push-notifications/index.js

Christoph Berlin

unread,
Dec 12, 2014, 11:10:06 PM12/12/14
to mobile-c...@googlegroups.com
Hi,

I apologize in advance if it looks like I try to hijack this thread - that is not my intent. However can someone outline how to implement push notification with the sync gateway? I found the Couchbase Chat app with its push notification robots but I cannot get it too work at all. In this project the code is outdated or at least I don't understand it all which could very well be. Despite the fact that I cannot get it to work I have no idea what sync-wrangler does and there is no documentation at all.

We are very well aware of the push notification requirements such as registering devices, etc. We have the infrastructure already in place - what we miss is the ability to "listen" to the database changes and trigger a push when a push is needed. 

In this thread people talk about sync-wrangler, forward and other tools but we would appreciate if someone could outline what needs to be done or how to the make Chat push node application work...

I truly appreciate your help.
Christoph

Traun Leyden

unread,
Dec 13, 2014, 11:43:37 AM12/13/14
to mobile-c...@googlegroups.com

Hey Christoph,

I have a complete working example you can look at.  Every time I go to our San Francisco or Mountain View office, I get picked up by an Estimote beacon and get a push notification.

It has the following components:

* OfficeRadar App Server (written in Go, runs in the Cloud)
* Uniqush Push Notification Gateway (3rd party server, runs in the Cloud)

The logic flow is as follows:

* iOS device comes in range of an Estimote beacon
* The app receives a callback from Estimote SDK
* The app saves a new GeofenceEvent document to Couchbase Lite (via a CBLModel)
* Couchbase Lite pushes this to Sync Gateway via continuous push replication
* Since the App Server is following the changes feed, it will see the new GeofenceEvent document

HTH!


Christoph Berlin

unread,
Dec 13, 2014, 12:37:48 PM12/13/14
to mobile-c...@googlegroups.com
Traun,

Awesome! As always your input is very much appreciated. I will review as soon as possible and get back to you.

Thanks Christoph

You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/EBuekY1Vizs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/CACSSHCGc3sTCQBoUtkzCgY6NkdnKWJHJrFVbDuW0n9e1xJCArQ%40mail.gmail.com.

Traun Leyden

unread,
Dec 13, 2014, 12:50:13 PM12/13/14
to mobile-c...@googlegroups.com

No problem.  

Btw, which server side language are you looking to use so that I can try to steer future examples towards that?


Christoph Berlin

unread,
Dec 13, 2014, 12:52:00 PM12/13/14
to mobile-c...@googlegroups.com
Well I am familiar with Node and the traditional languages…GO is new for me but I accept the challenge :)

Traun Leyden

unread,
Dec 13, 2014, 12:54:03 PM12/13/14
to mobile-c...@googlegroups.com
You should check out Jason Smith's library follow, which is written in Node.js.

Jeremy Kelley

unread,
Dec 13, 2014, 9:39:58 PM12/13/14
to mobile-c...@googlegroups.com
Just to threadjack a bit myself - Do you know of something like the
follow lib you linked (looks awesome) but written in Python?

Thanks,
Jeremy
> https://groups.google.com/d/msgid/mobile-couchbase/CACSSHCEGH-F4YcE3bEPQoGqHd1craLQsT09vcFSQU91BpjNFMw%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
The Christian ideal has not been tried and found wanting;
it has been found difficult and left untried – G. K. Chesterton

Christoph Berlin

unread,
Dec 16, 2014, 3:12:34 PM12/16/14
to mobile-c...@googlegroups.com
Hi Traun,

I just wanted to provide a quick update. Its working! We took your notification document approach, combined it with Follow and voila. Thanks much!

If I may provide a little bit of feedback. I may be wrong but it seems that the CouchChat example is outdated and not the recommended approach. Maybe mark it as such – I spent a day trying to get it to work.

Thanks as always
Christoph

Traun Leyden

unread,
Dec 16, 2014, 3:18:25 PM12/16/14
to mobile-c...@googlegroups.com

Christoph Berlin

unread,
Dec 16, 2014, 3:20:26 PM12/16/14
to mobile-c...@googlegroups.com

Frederic Yesid Peña Sánchez

unread,
Jan 25, 2015, 11:33:01 AM1/25/15
to mobile-c...@googlegroups.com
We are facing a similiar requirement:

Basically our workflow is:

1. Web application serves clients, they update data on their sessions
2. A cron job runs every 10 minutes and process ALL users who have logged previously on the iPad app and synces data between MySQL - Couchbase Server (Query Views directly from Couchbase, store data with Sync Gateway)
3. Sync Gateway does it's job and pushes data to devices.

That process makes several readings on MySQL and Couchbase Side

If we could implement "Follow", we could filter and only enqueue sync for channels affected in _changes feed, so not all users need to ve queried for changes.

But no idea how to process _changes feed from PHP side, as no idea of GO language.
To unsubscribe from this group and all its topics, send an email to mobile-couchb...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/D0B1B930.1BA2C%25cberlin%40christophberlin.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/EBuekY1Vizs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchb...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/D0B1BC92.1BA51%25cberlin%40christophberlin.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/EBuekY1Vizs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchb...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/D0B5D18B.1C20A%25cberlin%40christophberlin.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Couchbase Mobile" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mobile-couchbase/EBuekY1Vizs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mobile-couchb...@googlegroups.com.

Jens Alfke

unread,
Jan 25, 2015, 5:48:17 PM1/25/15
to mobile-c...@googlegroups.com

On Jan 25, 2015, at 8:33 AM, Frederic Yesid Peña Sánchez <freder...@gmail.com> wrote:

But no idea how to process _changes feed from PHP side, as no idea of GO language.

The Gateway REST API docs describe how to access _changes. 
Also, you can look up PHP client libraries for CouchDB and use those with SG, for the most part — the APIs are 90% identical.

—Jens
Reply all
Reply to author
Forward
0 new messages