Pregunta

I am trying to create a sample IOS app which posts location updates from a mobile device from the background to a rails backend which connects to a postgres database and presents a web frontend.

Workflow:

Basically when a user logs in via ouath on their mobile app, the app goes into the background and continues to send background location data to the server using the pubnub channel. So a user X logs into an app on his mobile, and user Y into hers, and they connect to a channel that puts them on the dashboard. Now a user M logs in to the dashboard and finds only user X and Y. Another user Z can login on his mobile but he uses a seperate channel(?) and so does not show up when M logs into the web dashboard but shows up when another user N logs in

So

X,Y ==== Channel A ===== User M (Web Dashboard) (Does not see Z)
Z   ==== Channel B(or channel A itself if possible) ==== User N( Web dashboard) (Does not see X,Y)

My question is three fold:

1.) Will I have to create seperate channels to implement this for each dashboard user and then connect them seperately?

2.) Is there background pubnub support to send location updates from the background(allowed on IOS7)

3.) The connection pricing is a little confusing , does anyone know how the pricing structure would be for an implementation that would look like above, per connection to any channel or per channel or other ways?.

I am assuming Ill have to enable pubnub presence enablement to do this.

Are there sample apps that do similar stuff (probably a chat application would like something like this). ? Pubnub has a lot of documentation on the API, but less samples.

¿Fue útil?

Solución

PubNub Real-time Network iOS Multi-user Dashboard GeoLocation App

This is a good question regarding creating an app that provides user location dots on a map. Basically user connects to a PubNub Channel using PubNub.subscribe() and will receive any LAT/LONG coordinates from other users. All users issue PubNub.Publish(LAT/LONG) code in order to a channel which is received by all users connected to that channel.

Splitting and Segmenting Populations via PubNub Data Channels

In order to segment the population you simply use different channels.

iOS Background Tasks Updated Location PubNub

You have several options to run background threads on iOS7. The recommended option is binding to the Background GeoLocation Change Event, then issuing a PubNub.Publish(LAT/LONG) in order to send the change. You'll bind on for iOS Multitasking: Background Location http://mobile.tutsplus.com/tutorials/iphone/ios-multitasking-background-location/ for didUpdateToLocation. The Background Location is extremely easy to implement.

locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];

// Increased Accuracy is used only when app is Visible/Open.
// Otherwise only significant changes are transmittable.
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

- (void)
locationManager:     (CLLocationManager *)manager 
didUpdateToLocation: (CLLocation *)newLocation 
fromLocation:        (CLLocation *)oldLocation {
    CLLocationCoordinate2D currentCoordinates = newLocation.coordinate;
    NSLog(
        @" NEW LOCATION: Lat(%f) Long(%f)", 
        currentCoordinates.latitude,
        currentCoordinates.longitude
    );

    // Define a channel
    PNChannel *channel_1 = [PNChannel channelWithName:@"a" shouldObservePresence:NO];

    // Send Lat/Long
    [PubNub sendMessage:@{@"lat":currentCoordinates.latitude,@"long":currentCoordinates.longitude}  toChannel:channel_1];
}

PubNub iOS Basics: https://github.com/pubnub/objective-c/tree/master/iOS#lets-start-coding-now-with-pubnub

Connection Pricing on PubNub

PubNub bills on Daily Active Devices metric. If the user was connected all day or at any point that day, then we increment a counter by 1. This is in a 24 hour window where we increment this number. After 24 hours the value resets to 0.

PubNub Presence

Presence on PubNub will provide you connection analytics on a Per-channel basis allowing you to detect total connected devices at the very moment, in real-time.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top