Pubnub for chat in ios - php

There is project which have chat feature which is been done by using PubNub. I had gone through the tutorial provided by PubNub and had integrated the pubnub.framework and CocoaLumberjack in my project. And had added the coded as shown in this tutorial
My questions are:
Do i have to create different channel to chat with the different friends? Or how the channel in the PubNub will work? I want to do only one-one chat. I don't want to implement any group chats. As per my study from using PubNub for multi users chatting every user have their own channel. But in that case how can I load the unread message count or messages when I am offline.
What is the process to install the PubNub server in my backend server? I am using backend as PHP Laravel.

you are free to create an unlimited number of channels, so for 1-1 chats, every user is subscribed to their own private channel. to chat with you, I publish a message to your private channel. here is a write-up that outlines this in more detail. for short periods of being offline (less than 10 mins), you can rely on the catch-up mechanism (make sure you configure this). for retrieving the actual messages while you were offline, you can use the history() function of Storage & Playback. retrieving only the count of unread messages requires logic on your end... perhaps keeping count of the number of messages published for each channel in your backend database, and then clients can make a REST call to your backend to retrieve this count.
PubNub has a PHP SDK you can use... what do you plan on having your backend server do?

#Alex is right and here is some more clarity on that:
Every user should have an inbound channel that they subscribe to and anyone that wants to invite them to a private chat publishes an invite message with the name of the new 1-1 chat channel, in that message. If the invited users accepts, that user will subscribe to the new 1-1 channel, else a decline message can be returned on the inviter user's inbound channel.
For any channel that a user needs to know the number of messages missed while offline (or just not actively subscribed to a channel), you need to call history on those channels with the timetoken of the last received message on that channel. This will retrieve the messages and you can just get the size of the array of returned messages to display that unread message count.
There is no PubNub server to install. Your PHP server app/script will use the PubNub network in much the same way that your iOS client apps use it. There is just the PHP SDK that you have to download and requre:
PubNub PHP Composer
PubNub PHP (non-Composer)
PubNub PHP Larvel (NOTE: third party - PubNub cannot provide support for this but it might provide some insights into using PubNub with Laravel)
You can think of both your server and your client apps as clients of the PubNub Network. Your PHP app will likely on publish messages on channel but not subscribe to channels, though. If you are thinking you need to subscribe to channels from your PHP app, please contact PubNub Support with details about your use case.

Related

Send FCM message to specific Google user without need to install an app?

I'm doing a tiny personal project involving an Arduino and a PHP backend. I want to send a push notification from the PHP backend to my Android phone using Firebase Cloud Messaging. This question is specifically about FCM - I don't want to use any other services like Blynk, etc. I also do not want to send the notification directly from the Arduino, but rather from the PHP backend.
Can I send a FCM notification to my phone without having to create an app to receive it? I'm logged in with a Google/Gmail account on the phone, and I have no need to target any other users than myself.
Can I send a FCM notification to my phone without having to create an app to receive it?
No, this is not possible. It would open users up to some pretty hefty abuse.
In order to receive your notifications, the user must have your app installed.
Mind you, this can be a pretty minimal app, since the default implementation of FCM already displays notifications to the user if the app is not active. So really all you have to do is create an empty app that includes the Firebase Cloud Messaging SDK.

Do I need to make 2 different applications for using GCM in android?

I tried searching these issues. Some sites say I need to do some stuff with php in order to make 3rd party server while others don't mention anything. some says it need JSON. Guide me please. PS I am a beginner and know java, XML,SQL only.
You should only need one server. The second server you are reading about may be the Google GCM cloud server? When I did a GCM project a few years ago, I had one server, it happened to be a App Engine instance. It generated events and sent them to Google via the GCM api and then onto onto the device. I don't remember it being that difficult.
I did have more than one server in the mix though, there were others that sent messages to the AppEngine server, but it was not required to send a GCM message.
Google Cloud Messaging (GCM) is a service that enables developers to send data from servers to both Android applications or Chrome apps and extensions.
So if you want to send data to the users of your App then you must have an interface or dashboard from where you can send some data (typically push notification) to the users of your app.
This dashboard (server from which you can send data) can be developed by using PHP or any script languages.
Now a though can come up in your mind:
"I am suppose to develop both the mobile app and the server then what
role does GCM play?"
Yes, GCM is playing a vital role indeed. The server we have to develop is just to design an interface so that you can type your message/notification and select the recipients. Rest of the part of (managing the queue, communication with the apps checking for authentication and all other stuffs will be done by mighty GCM )
In order to have an bird-eye overview you can take a look on this image collected form android hive
Server side coding is doesn't need you to be expert in php. So you can go through to this article. It helped me a lot to learn.

Windows azure push notication and catch the notification to a particular website page

Hi im working on a project who has an existing iOS app that uses windows cloud platform. Our task is to create a website for the app. One of the requirements is to enable to catch notifications created by the mobile app. For example if there is a new user, push notifications will be triggered and a website link will catch the notifications and save the data to a database. My question is, is it possible to catch a notification from windows azure push notification using a php script event listener?
I don't have any background on windows azure and i don't have any access to there windows azure account. The only thing they said is to give them the link of the script that will catch the notifications.
What are some steps thats need to be done?
Thank you
I'm not sure this is possible. Notification Hubs sets up communications so that you can send a notification out to a many different platforms at one time (Apple, Android, Windows Phone, Windows 8, etc.). Each device registers with the Notification Hub (or the registration is done for them by a back end) and provides a unique device ID, also known as a Channel URI. When you need to send a notification the Notification Hub then disperses that notification out to each of the correct Platform Notification Systems (PSNs) which then deliver the notification directly to the device.
I say all of that to indicate while it might be possible to register a listener that is not a device with the notification hub using a REST based API (You'd have to create a viable channel URI) I'm not sure there is any way to be listening as a php script to a PSN. Also, the registrations do expire from time to time and so you'd need to make sure to keep registering. Finally, no notification system is 100% guaranteed to deliver a notification. The device could be off, it could be in a bad reception area, bad network connection, or the PSN just doesn't delivery it for some reason, etc.
My suggestion is to take a step back and modify the code where the notification is being produced and send it both to Notification Hubs for device distribution, but also send the content of that notification to your database directly, or have them right the message to a queue which is processed in the backend to save to the database if the database isn't local to the code generating the notifications. This removes the notification hub involvement as far as your website is concerned.
If you really MUST look into the php script getting the messages then you can start by trying to figure out how php can receive messages from the PSNs, which is not an Azure issue. You can use the Notification Hubs REST APIs to register for them, but I'm very skeptical of that route.

whats the best way to implement real time push messages with apache, php and mysql only?

i'm trying to implement a chat application for android (where users can communicate people who are in same location). i'm thinking it of an facebook messenger with Geo specific oriented. i came across to terms like repeated pull, comet, bosh, websockects, socket programming, xmpp(which requires xmpp capable server like openfire) etc to do this. But my resources are fixed like apache, php (codeignter) and MySql only. I need to find the efficient to way to do this. Guys i need this. Please help me.
Thank you,
abbiya
The preferred approach on Android is Google Cloud Messaging.
Google Cloud Messaging for Android (GCM) is a service that allows you
to send data from your server to your users' Android-powered device.
This could be a lightweight message telling your app there is new data
to be fetched from the server (for instance, a movie uploaded by a
friend), or it could be a message containing up to 4kb of payload data
(so apps like instant messaging can consume the message directly).
The GCM service handles all aspects of queueing of messages and
delivery to the target Android application running on the target
device. GCM is completely free no matter how big your messaging needs
are, and there are no quotas.
Essentially, it works like this: Your server talks to Google, and Google pushes the message in real-time (or nearly so, as long as the device is powered on and connected to the Internet) to the Android device(s). There's a registration process that happens on the Android device the first time the app is installed (and at future points to revalidate the registration). In your Android app, it's your responsibility to send this registration ID to your server so you can store it for future use. Your server uses this registration ID when it wants to push a message to that device.
The communication protocol between your server and Google is JSON over HTTPS. Your server can use any languages/technologies, as long as it can communicate with Google's servers. A PHP/MySQL application can definitely meet the basic requirements for the service:
Before you can write client Android applications that use the GCM
feature, you must have an application server that meets the following
criteria:
Able to communicate with your client.
Able to fire off HTTPS requests to the GCM server.
Able to handle requests and resend then as needed, using exponential back-off.
Able to store the API key and client registration IDs.
On the client side, the Android device must be running API version 8 (Android 2.2) or later. Of course, it's also your Android app's responsibility to process incoming messages (using a BroadcastReceiver, as the Android system sends an Intent to your receiver whenever a message arrives), which allows you to handle messages however you want.

Pubnub multiuser chat

I am developing a multi-user chatting system in php.
I know about push and pull, reverse ajax, comet etc. but mostly we have to configure over our server.
However, I can't access my server to install those scripts because I have shared hosting provider.
So after some research I came to know that pusher, pubnub provides api to have push data on browser.
The question is about pubnub, that they are providing channels to send data to clients, but problem is I want to develop multi-user chat in which the data will sent to only one user not like multicasting chat.
As I think one solution is that to make a unique channel per user, so that data will only sent to that user, but this doesn't seems to be efficient. so any other way to implement multi-user chat system with pubnub ?
or any other suggestions that are better ?
Multi-user Chat System with PubNub
Get Started - PubNub best practice: How to manage private rooms?
You are asking about a Multi-user Chat system with PubNub where the communication style is one-to-one between two users with parallel conversations. Great news! PubNub has a service called PubNub PULSE - provides One-to-One style communication ideal for your Multi-user Chat - http://www.pubnub.com/price (see PULSE section).
PubNub Best Practice - How to manage Private Rooms
Also there is a conversation started here which Mikita mentioned on how to create Multiroom Chat Service, likely similar to Facebook Chat, where you are able to join and sit in on multiple chat rooms - PubNub best practice: How to manage private rooms?
EDIT - UPDATED INFO - MARCH 2018
You use of one channel per user is not inefficient. Use as many channels as you like. They cost you nothing more (or less) with respect to how many channels you use.
The pricing plans mentioned above are obsolete. Please review the PubNub Pricing and the Move Away from Device Counting.

Categories