When I am connected to internet then It works perfect but when Internet is not connected then I go error on following lines:
$socket_context = stream_context_create($options);
$this->smtp_conn = @stream_socket_client($host.":".$port, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $socket_context);
I am intentionally not connected to internet and i want to show alertView
in iOS app to user when user is not conneted to internet that :
You are not connected to internet
Instead of
Warning : stream_socket_client( ) , php_network_getaddresses getaddrinfo failed nodename nor serv name provided or notknown
So how can i handle that error ?
// -------------- Code where I am setting NSStream in .m file :----------
#import "LoginViewController.h"
// --------------- here I set the delegate -------------
@interface LoginViewController () <NSStreamDelegate>
-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{
}
Any help will be appreciated.
Assuming you are using NSStream to connect your sockets. In your delegate method
You will be notified if the socket has an error with:
or
In which case you can show the network error to your user. If however they lose internet connection you won't know until you try to send some data over the socket. So to get around this problem you should implement Reachability.
Github project
or the Apple helper class.
Apple Reachability
You will be notified when there is no connection as well as when there is a connection allowing you to notify the user as needed.
Hope I understood correctly.