Host page locally on iOS - ios

I didn't know it was possible on iOS but lately I went to Japan and one of the free wifi apps wanted to install profile into my iPhone. When I confirmed installation it simply opened Safari with 127.0.0.1. It loaded some page and downloaded profile from there. How do I host some page on iOS?

Creating web server is nothing hard. It is lot of coding of course, but the principle is pretty easy.
There is lot of 3rd party libraries on the github (GCDWebService) just try to search for "ios http server"
To create it manually you need few steps:
1) With the help of CFSocketCreate you open new socket with specific port (standard HTTP 80, or secured one 443 should be forbidden without root access rights) what going to listen on network interface on incomming requests.
2) You need to prepare some receiver what will be triggered as soon as some request income. You can use NSFileHandle class and register NSFileHandleConnectionAcceptedNotification in your notification center. And allow background mode with acceptConnectionInBackgroundAndNotify method. But I recommend to read the manual first
NSFileHandle Apple documentation
3) Process the incoming request. The selector what you register is called and in NSNotification.userInfo property is the incoming request, and you can generate some page here and open it in safari, or in your app or do whatever you want.
4) If you want received some POST data or streams, there is needs to register NSFileHandleDataAvailableNotification what trigger selector as soon as some data to read are available.

Related

Notify user when connection is lost

An app I made connects to a database to retrieve and send data. Now, if the user has no Internet, it is the intention that the user is warned and sent to the start page.
If there is a solution for this on the service, the components are:
DSServer
DSServerClass
DSTcpServerTransport
On the client-side, a connection is made with a TFDConnection.
I know there is a way to check the session if it is active or not, but I don't know how to put this in code.
With the demo of Dave Nottage, we managed to check if there is an internet connection.
Don't forget if you use it on android to add the .jar file in the library of the android
SDK.
Klik here for the demo of Dave

Firebase insecurity/public endpoints with iOS app

I've frequently heard that the main issue we need Firebase security rules is because an application contains all the configurations needed to connect to the database and thus users could do something like db.delete('*'), read/write whatever they want, etc. etc.
I can see how this is possible on a web app, as you could check out the requests being sent over the network and thus get the endpoint needed to connect to the database, but, on an iOS app, how would this be possible?
For instance, say I created some chat app with Firebase and released it to the App Store. When a user downloads it, how would he/she gain access to my database through an API other than the buttons etc I provide with them with? Is there something equivalent to the "Network" section in google chrome that shows all outgoing requests, and, from, this they could send a malicious request to my database? Would this require installing 3rd party software onto their device to see all outgoing/incoming requests and they could get the required endpoint/database connection info from there?
Thanks.
When a user downloads it, how would he/she gain access to my database through an API other than the buttons etc I provide with them with?
It's not hard to reverse engineer the contents of the IPA file to get both the configuration you provided, and also see what the code is that queries the database. The IPA file can be obtained pretty easily - there is not much protecting that, given the user effectively has full control over the device (e.g. jailbreak). Given that information, it's possible to simply invoke the public Firestore REST API to not just duplicate all the operations in the app, and but invent operations of their own.

update tableview if data is changed online

We are making an app for the hotel where we have already made an app where orders can be placed through app. All those orders can be seen on web portal by refreshing the page.
Now client requested to create an app where waiter can see the order on his iPad.
For that we will be having the tableview where all list of orders will be shown.
However I am not getting how I will refresh the table/ add the data if new order is made.
In short once order is made, at same instance waiter should get alert and table view should be updated.
Note: iPad/ iPhone get the data through webservice.
This can be achieved by calling webservice every 1 min or 30 seconds.
However I don't want to do this way...
If new stuff is added, webservice will send that data and I will add that data in my tableview. Means webservice will send me listener that new data is added
I need to know how can I listen this listener if webservice send me listener.
Any useful info on this would be appreciated.
Below link helped me for TCP in iOS.
http://www.tekritisoftware.com/sites/default/files/Socket_Programing_for_IOS.pdf
You could implement it using a TCP-based client-server approach, where the iPad is the client.
The iPad client connects to the server using authentication so you know which waiter is using the iPad.
The TCP uses duplex communication over the TCP socket so either side can send a message to the other.
If the server has something to give to the iPad/client/waiter then it simply sends it to them.
If the client wants to send a message to the server, like "I'm taking a break", or whatever, then it simply sends it to the server.
The range of information you can share between the client and server is actually unlimited.
There is no 6.
This requires the server to be written as well, however, so this solution is more than just iOS development. However a webservice would need similar development anyway.

Push Notifications through BES/BIS , BlackBerry

I am trying to use push notifications for OS < 7.X .
I downloaded the sample server / client code. I deployed the client code on my device and the low-level-sample code on the tomcat provided.
For the record , when i registered for push notifications here i registered using the BIS option. Now that i was actually given a blackberry i was informed it is using BES ( i dont think though this is the root of the problem that i am going to describe..).
On the device , in the sample application i put all the correct settings given from the email i received.
Both my pc which is running the tomcat server and my phone are connected to the same wifi.
I am trying from the device browser to connect to the server , eg https://196.84.32.112:8443/low-level-sample
and the browser opens the page normally , meaning that i am able to connect to my server from the mobile.
Now when i hit register from the device sample app ( i have tried both BIS/BES options on the settings ) , i always get the following error :
Request to register failed. Cause by java.io.IOException: Network operation[Subscribe] failed. Make sure that Content Provider URL is accessible.
In the log i get :
Opening URL: my server url appended with info like username/password/model/connection type etc
Content Provider network command [ Subscribe] failed , caused by could not connect to 196.84.32.112:8443
Command "register" failed with error: java.io.IOException: Network operation[Subscribe] failed. Make sure that Content Provider URL is accessible.
A thought is that i should register again for new push keys and use the BIS/BES option instead of only BIS , but here the problem seems to be no connectivity with the local server , not the RIM server. I already tried to register though and i am waiting for the mail with the new settings.
Also i am a bit confused with the BIS / BES option. I have no idea if my users will have BIS or BES enabled so what do i put in my code ?! In the sample application it asks me to select between BIS or BES but when the app is going to production and i need to programmatically make that choice what will i choose?! Or this choice is made only for the evaluation/development of the app and on production there is another server ?
I think all the right things have been said here, but I'm hoping we can consolidate some of the answers, and wrap this question up.
You haven't shared your code, which makes things more difficult, but many people use the RIM/BlackBerry provided PushDemo source, where a connection suffix is hardcoded in /pushdemo/com/rim/samples/device/push/PushUtils.java:
private static String getConnectionSuffix() {
return ";deviceside=false;ConnectionType=mds-public";
}
I'm also guessing this from having read your other question.
By doing this, you've hardcoded the BlackBerry transport type of BIBS. BlackBerry supports many different transports, like BES, BIS, BIBS, or WAP. The BIBS transport will send the request from your device, out to BlackBerry's servers, which are on the internet. (Note: this part is probably confusing to an iOS/Android developer, since those platforms don't provide Apple/Google network intermediaries to relay normal HTTP/S traffic)
Then, the request is relayed to your server, which is at:
196.84.32.112:8443
I'm pretty sure that TCP/IP endpoint is not available from the Internet (I can't reach it). So, that's why it fails for you.
You can take this URL
https://196.84.32.112:8443/low-level-sample
and paste it into your BlackBerry device's browser, and it will work. Your device is configured for BES, which uses your company's internal servers. Those internal servers can reach the 196.84.32.112:8443 endpoint, so it seems to work for you. But, that's because you haven't hardcoded the transport, as you have in the push code that uses getConnectionSuffix(). The device browser is smart enough to figure out a transport that works, and BES works to reach that intranet server.
Hopefully, that explains the confusing part.
Solutions
As others have said, a solution is to get your company's IT people to make IP address 196.84.32.112 and port 8443 accessible through their firewall. That would allow the BlackBerry servers to reach it successfully.
Another solution would be to change the PushUtils.java code to avoid the BIBS transport:
private static String getConnectionSuffix() {
return ";deviceside=false";
}
If you want really flexible code, then I'd suggest rewriting that PushUtils.java code, because it appears to use the pre-5.0 HTTP connection logic. ConnectionFactory in OS 5.0+ makes this easier, and more robust, when supporting multiple transports ...
To answer your question about supporting users with multiple transports, take a look at this blackberry.com example, specifically the MyConnectionFactory class. It allows you to select which transports your app allows, and which it tries first.
Ultimately, the decision to make your server public or not depends on how it's going to be used, and whether you'll have non-corporate internet clients trying to register with your corporate server.
Let me first explain the registration flow for BB Push Demo:
When you click on Register the device will
Inform your web application that the device wants to register. For this it will send the information about the device to your Web Application (the so called ContentProvider). You are expected to store that information in your database. This step happens in the ContentProviderProtocol.performCommand() method of the push demo.
Inform the BB Push Server that the device wants to register for receiving push notifications from your application. This happens in the BpasProtocol.register() method of the push sdk.
Step 1 is only necessary if you want to know who all are registered for push notifications (maybe if you want to send individual push notifications to each device and not broadcast the message to all registered users). In that case, you will probably need other information like that user's preferences etc for customizing the push anyway.
Now the error you are getting is from the step 1. For step 1 to succeed, your device should be able to connect to your web app which it is not able to.
To solve this problem, either you have to make your web app publicly accessible (and be ready to handle the load) or comment out the step 1 from the app by making ContentProviderProtocol.performCommand() return without doing anything.
PS: The webapp used in step 1 need not be same as your push initiator. The webapp is simply being used for tracking who all is registered for receiving the push and should ideally be located in the cloud on a distributed architecture if you expect a lot of users.

If a UIWebView displays a remote page with a username/password then can the native code tell if/when it has been validated?

I have a requirement for an app to communicate with a server, this communication is done using a proprietary http based protocol and the app uses NSUrlConnection for this.
However before the app can be used the user must first perform a one-off registration, and the requirement is that this is done by them logging onto a web page which will be downloaded and displayed in a UIWebView. As a UIWebView is used I no longer have access to the HTTP header/body nor the NSURLConnectionDelgate etc. for this part of things.
My question is, how can the app know if and when the user has successfully logged onto the web site?
It sounds like you want to implement some code in the connection:didReceiveAuthenticationChallenge: method of the NSURLConnectionDelegateProtocol. There's more information about how to respond to a challenge here.

Resources