ios push notification do not show up always - php

I am an iphone developer.I am trying for push notification . I created certificates,provisional profiles and php script.And i try to run in terminal,then it work nice.But when i upload it in my server,notification come sometimes mostly it show following error
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused)
Failed to connect: 111 Connection refused
I placed the ck.pem file in the same directory of php file. Does it require to add the path?

it seems you lose the connection during the push notification, and yes you should add the path
make sure you double check that the port your using is correct and open.

Also note that Push notification is also not always guaranteed. You can refer 'More about Push notification' section in https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html
Quality of Service
Apple Push Notification Service includes a default Quality of Service (QoS) component that
performs a store-and-forward function. If APNs attempts to deliver a notification but the device
is offline, the QoS stores the notification. It retains only one notification per application
on a device: the last notification received from a provider for that application.
When the offline device later reconnects, the QoS forwards the stored notification to the device.
The QoS retains a notification for a limited period before deleting it.
If a device is offline (either turned off or just unreachable) then it will receive at most a single push notification you attempt to send to your application during that time.

Related

Keeping socket open in Swift for chat application

I have a working chat server in Php/Ratchet. I am using Starscream as my client in Swift. I successfully created a chat between users however this only works when my application is open because this is when the socket is open. How do I make my app receive messages even if my app isn't on. So basically is there a way to keep sockets open. I read somewhere that it is forbidden by Apple.
There's a high probability that your process is going to be shutdown by the system at some point, so I wouldn't rely on the app being active in the background.
Try coming up with a solution for receiving past messages when the client becomes online.
Read about Apple Push Notification Service to notify your users about messages while the app is not active.
Sounds like you are sending messages from your client to your phone. You need to send messages to a server and the server sends them to your phone.
The server, if unable to successfully send a message to your phone, should store the message and should send the stored messages to the phone when the phone is available.
There are message queuing systems for things like this. See, for example, RabbitMQ. There are loads of others too that may work better with your tech stack. Do some research.
Here the client talks to the server, the server hooks up with RabbitMQ or whatever you choose to use, RabbitMQ keeps a track of queued messages and when the phone comes online, RabbitMQ sends the queued messages to the server and the server sends them to the phone.
PS Google "message queue PHP".
You need to be in sync with server. Do following steps.
Dump every message in Database i.e. conversation from both parties with timestamp.
When app goes in to background and comes to foreground flush your all messages which are on your screen/local array for showing messages on screen, call a Sync service which will fetch whole conversation, because definitely server will be having all messages, feed you screen with this service response.
The iOS system will receive socket calls at kernel level but will not pass those messages to you app, so you will not get messages while app is in background.
When app is killed you can implement APNS from apple.

iOS APN Php Cannot Connect

I followed this youtube tutorial on how to send push notifications: https://www.youtube.com/watch?v=_3YlqWWnI6s
When I run the php file on my webserver however it times out giving me this error. I have looked at the web and nothing I could find seems to be the problem, can someone suggest where I have gone wrong..
[14-Dec-2015 06:13:10 America/New_York] PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /home2/sptechno/public_html/Wink/sendPush.php on line 18
when you run .php file for Apple push notification.
That time you need to check the TCP/UDP Port number is open on your server other wise notification not pass to apple server.
General Provider Requirements
As a provider you communicate with Apple Push Notification service
over a binary interface. This interface is a high-speed, high-capacity
interface for providers; it uses a streaming TCP socket design in
conjunction with binary content. The binary interface is asynchronous.
The binary interface of the production environment is available
through gateway.push.apple.com, port 2195; the binary interface of the
development environment is available through
gateway.sandbox.push.apple.com, port 2195.
Apple official document for that.
EDITED
Check for your server is connected to APNS.
HOSTGATOR:~ Home$ telnet gateway.sandbox.push.apple.com 2195
Trying 17.149.34.143...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.

iOS - correct way to send push notification to multiple apps from the same server at the same time with the same message and payload

I have two separate applications in "development", lets call them App A and App B , that are supposed to receive the exact same message and payload from the same server as a push notification. Both have different application ids, certificate requests, provisioning profiles, development APN certificates, and produce different tokens.
If I send a push notification to either application individually each application will receive a notification. But if I try to send a push notification to each application concurrently, only the fist application will receive the notification. But I will receive no errors for the other application.
I have tried to delay the push notification by up to 10 seconds between sending the push notification to the last application without success. Is there some way that I need to handle the connections to the apple server to enable this type of push notifications?
Also note that there is another question that is having the exact same issue, but without any answers. Limitations on push notifications for multiple apps from the same server
I was able to get the notifications to be delivered to both of the applications successfully by closing the previous connection. This is not recommended by Apple, and they state that I should keep them open, as there is a potential to have a lot of notifications pushed per day to each application.
Keep your connections with APNs open across multiple notifications; don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack
Read More Here
try to use two instance of your server , and keep your connection open while sending.
Connect each instance to a different port: 2195, 2196

J2ME PHP Push Notification

I want to work on a project which has to do with the server sending notification to the client. The client side is a j2me application and the server side script will be implemented using PHP.
I have found out i can use the push registry API in midp 2.0 for push notifications, but i don't know how to implement this such that a socket connection will be created to the server such that notification can be sent to the client via the socket connection. The notification will then trigger the start of the midlet.
How can i use the push API to create a socket connection between client and server and have notifications sent to the client?
Complete answer is here
In short, there are two ways you might want to do it
Launch the application whenever you receive this "Push SMS"
Launch the application just the next time you receive this 'Push SMS"
For situation (1), you will need to specify this in JAD file. If you do this, the application manager will take necessary steps to launch your application the next time SMS is received.
For situation (2), you will need to write code:
PushRegistry.registerConnection("sms://<port number>","Midlet-Class","*");
The above note of mine would address the issue of launching the application upon incoming SMS. After you launch you can connect to your server and post data or retrieve data. This is a practical way of implementing push for J2ME platform.
But you seem to be wanting to launch the application on incoming network connection; this means you are creating a server socket on the phone and server is trying to establish the connection to the phone applications. I did work in such a situation where the phones were deployed on Motorola's iDen network (pre-2005 era). On such networks, it is possible to assign an IP address to the phone which makes the Push upon incoming network connection feasible. But that's past, on none of the GSM/CDMA networks, atleast at consumer's end, this cannot be supported. Hope it answers your question.
You need to do two things, One you need to listen one port number on the J2ME side for the incoming sms. Next you need to attach one GMS Modem to your computer system, Now send sms using this Modem on a particular port to the mobile you are listening. You can use AT Commands to send SMS.
Please visit this Nokia Link.

Apple Feedback Service (APNS) is slow

I have coded Push Notifications (APNS, Apple Push Notification Service) for an iPhone App with PHP. Everything is working fine while no app is deleted from a device. I use the Feedback Service from Apple do get the deleted devices. If I get devices I mark them as INACTIVE in my database to send no further push notification to those devices.
The problem is that Apple is slow. If you delete the app from your device a request is send to Apple and I collect the devices by using the Feedback Service. But Apple is not forwarding the inactivated devices instantly so I get the following error because I can't send push notifications to a inactive device:
PHP Warning: fwrite(): SSL: Broken pipe in apns.php on line 155
My Feedback Service script runs every 5 minutes but the update from Apple comes every 10-15 minutes. If I send a push notification within the 10-15 minutes the above error appears because in the database the device is still marked as ACTIVE and on the Apple server the device is marked as INACTIVE.
There is no problem to connect to the Feedback Service or to the Push Service but I don't always get devices from the Feedback Service.
Greets,
TheFox
Answer from Apple.com Developer Forum (https://devforums.apple.com/thread/114446):
Your server needs to detect disconnections and reconnect if necessary. Nothing is "instant" when networking is involved; there's always some latency and code needs to take that into account.
Also, consider using the enhanced binary interface so you can check the return response and know why the connection was dropped. The connection can also be dropped as a result of TCP keep-alive, which is outside of Apple's control.
So I'm gonna set all devices to INACTIVE if the server detects a disconnection.

Categories