WatchOS establish server connection - swift

I have a client - server IOS application. In addition, I need to write an application for it on WatchOS. So I have 2 questions:
When I send a command from Apple Watch, do I need to connect to the server from the watch or transfer information to the IOS application and connect to the server from the phone?
If I have to connect to the server with an IOS application, then how can I connect in background mode?
As an example, you can take any messenger, for example Telegram
If I reply to a message with AppleWatch, how is the message being sent to the server (Via iPhone or directly via AppleWatch)
For connection to the server, I use the "Starscream" framework
Maybe I don't understand something, but Apple made it impossible to establish a connection in background mode
I would be grateful if you tell me or provide examples and articles, so that I could understand what to do.

Apple Watch apps can connect directly to servers using URLSession ... no need to go via the phone.
Here is an example on using URLSession in Combine, which is the "latest and greatest" way of doing things.
Otherwise this example shows using it in a more conventional way, with the bonus of SwiftUI.
Otherwise

Related

Socket connection between rails and iphone native app

I have an iphone app with rails serving as a backend server.
Now I need to implement a chat functionality using sockets connections.
A lot of examples show you how to implement chat using sockets in browser.
What I need here is how I can implement an application where you create socket server in the rails app , and the client in iphone app which listens to the channel I give them.
I tried using faye(examples given only how to implement client in the browser) and using fayeObjC library for iphone to create client, but am not able to listen to the channel from this library.I know I must be implementing it wrong here.
I'll share my code also here, but first I need to know is there a better solution than this?
Also I appreciate some links to some examples where socket server is in rails and clients are iphone app.
Appreciate any help and mostly need a right direction to implement it.
Update
I tried the faye combination again and it worked.Although still looking for more solutions.
You can check about TCP sockets:
http://www.raywenderlich.com/3932/how-to-create-a-socket-based-iphone-app-and-server
Chat Application Using Ruby
http://quickblox.com/modules/chat/
http://caydenliew.com/2011/11/ios-mac-os-communication-with-asyncsocket/
http://www.macresearch.org/cocoa-scientists-part-xxix-message
Next link is a comprehensive Networking Guide - Using Internet Sockets
You must keep in mind two major problems to peer-to-peer communications (Chat): reachability and how to receive new messages while your application is in the background (get notifications).
For the last you can use APNS approach: an invisible notification will be pushed to the iPhone indicating that a new message is ready to be read. So your app will make a request for unread messages (what app like WhatsApp does).
Besides TCP sockets you could use websockets (HTTP - so there are no firewall problems).
Best in class - Socket.IO.
Here you will find the wiki https://github.com/learnboost/socket.io/wiki (you will find there an extension for Ruby also)
Here an example for iOS chat client for socket.io & node.js backend
Jabber
Another option: XMPP - "stands for eXtensible Messaging and Presence Protocol. Such a protocol is open-standard and oriented to message exchange (builds and maintains by Jabber community). Message exchange happens near real time, so it is an ideal infrastructure to build chat-like applications. The protocol also implements a mechanism to notify presence information (whether a user is online or not) and the maintenance of a contact list. XMPP is a thorough protocol, which has been adopted also by big companies like Google to build their Instant Messaging service."
Here you will find all about developing a Jabber Client for iOS (enable users to sign in, add buddies, and send messages; how to install and configure a jabber server, create accounts, and interact with the server from an iOS application http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/
I know that SocketRocket by square is a strong native Objective-C library. But it doesn't offer the channel abstraction you seem to be looking for.
If you would consider outsourcing the WebSocket connections then you could use a hosted service like Pusher, who I work for. You can publish messages (trigger events) on channels using the pusher-gem. And you can subscribe to channels and receive messages using one of Pusher's Objective-C libraries.
Other solutions will also have Objective-C libraries and you can find a list of them via this realtime web tech guide.

Anyone using XMPP to implement Push Notifications on iOS?

I'm looking for any reference projects or key learning from anyone who has implemented XMPP/Jabber to successfully send notifications to iOS devices (iPhone/iPad).
I'm considering using an XMPP server (OpenFire specifically) to provide a single cross platform mobile push system. C2DM for android has a number of annoying requirements like users having Google accounts. This is what got me started looking at XMPP. I also need to support pushing to iOS devices. I know all about APNS, however I'm wondering if I could use the XMPP server for both Android and iOS platforms (and possibly more like Black Berry).
The things I feel might come up are:
iOS killing any persistent connection to the XMPP server. Will it
auto reconnect?
iOS preventing access to certain ports or protocols.
Anything to be aware of here?
Other gotchas one would only discover
by trying this?
Here you can find the answer to your first question:
when your app goes in background you (the client) close the connection
with the xmpp server. When your app comes back into foreground you
reopen the connection. If your server need to send messages to your
client, it must use push notifications. When the client receives the
notification can (it depends on the user action) go back to
foreground.
(source: iOS Backgrounding & XMPPFramework)

Prevent from specific app using internet connection

I have a client claims that my app can't connect to internet despite of he has WiFi connection and Safari application, for example, works fine. Is there any way to setup for specific app NOT to connect to the internet? I use in my app simple ASIHTTTPRequest library to make a connections. Maybe it influenced by jailbroken device? Regards!
No, there is no way to do this in via an iOS setting.
However I've had a problem like this with a client, where to Webservice the app connecting to was blocked by there firewall/proxy.
Later the black was lifted but all calls to the webservice where is cached by the proxy give really weird results.

iPhone - Browsing iPhone files through computer

I want to be able to send files from an iPhone app to a computer. What would be the easiest way of doing this?
I've made simple server client programs before, but in those, the client has always needed to connect to the server before being able to receive messages from it. There is an app for the iPhone called iSimulate, where you put a server on a Mac (the iPhone simulator), and then you use the iSimulate app of an iTouch or iPhone to send touch events to the server. This app does not require you to type in an ip-address. Instead it presents a list of available computers that have this server up and running.
How exactly is this being done? Can a server broadcast a message over a network, w/o anyone being connected to the server? How does that work? How does a client listen for that broadcast?
Here's a video of the app I'm talking about:
http://www.youtube.com/watch?v=N3Qpd1ycZh4
alt text http://a1.phobos.apple.com/us/r1000/051/Purple/7b/07/70/mzl.mvwjifyc.320x480-75.jpg
That app may be using Bonjour.
I've seen similar apps use a peer-to-peer Bluetooth connection to exchange files between a iPhone and a desktop.

Secure iPhone-Desktop Connection

Background
There are a lot of App Store released iPhone apps that require an IP based server on the desktop so that the iPhone can connect to the desktop as a client. For example, there are many programs that emulate a keyboard, touchpad, or Apple remote on the iPhone so that a desktop computer can be controlled over wifi. However, many of these applications get around writing their own server by requiring the user to install some VNC server variant.
Question
What is the best way to implement a secure (encrypted) IP server on a desktop (Mac and Windows platforms) that allows for simple two way message passing between itself and an iPhone client on a wifi network?
Sample Use Case
An event on the desktop causes the desktop to push a small image or text to the iPhone. An event on the iPhone causes a short text message to be pushed to the desktop. Any single event can happen at any time (doesn't appear synchronized to the user).
1st Follow-Up Question
Would this type of project be best handled using something like XML or JSON over HTTP? Or is there a better protocol, like BEEP or Bonjour(XMPP)?
What is the best way to implement a secure (encrypted) IP server on a desktop (Mac and Windows platforms) that allows for simple two way message passing between itself and an iPhone client on a wifi network?
Not sure if there is a "best" way, but much code is already available to do xyz-over-HTTPS (TLS/SSL). In that case, the "xyz" can be any web-based message exchange protocol, such as XML, JSON, etc. via REST or SOAP, etc.
If you want to be able to push events to a non-jailbroken iPhone you can't do it other than via Apple's Push Server which causes a notification to the client program if it is running or otherwise displays an alert of some kind to the user.
Typical architecture has those notifications handled by the client program as an indication it should go and get some data from the server - Apple insist we do not regard the notifications as trusted delivery.
I suggest a read of this article on using Bonjour and local networking, whilst it's iPhone to iPhone it should apply to desktop OS/X also.