Assuming I have permission from the user, is it possible for my server to trigger an action on my app on my user's phone? Does the phone have to be unlocked?
I want to make calls to the keychain API using both crons and manual requests.
If it is your app on the client, then you can do anything that is in the capabilities of the application. Are you asking for a hosted webview in your application?
If the phone is unlocked and the app is running, then yes you can have a two-way connection to a server, using either the TCP protocol or the WebSocket protocol. Otherwise, no.
Related
Since iOS 14 there is a Local Network Permission and Apple recommends to use waitsForConnectivity on the connection to wait for the user to answer the permission pop-up.
To check if a connection attempt is waiting for the permission Apple recommends the unsatisfiedReason property here to check for localNetworkDenied.
I tried to adapt Apples recommendation to Alamofire but couldn't think of anything.
My specific use case is an iOS app which connects to a server on the internet but sometimes the iOS device visits the home network of the server. For the latter it needs the permission and I want to give a good error message to the user if they revoked the local network permission (because in this case the iOS permission dialog doesn't appear again).
How can I archive this with Alamofire?
Alamofire doesn't provide a wrapper for NWPathMonitor, which seems to be what you're talking about. You can just use it directly and start your network requests once the status changes to what you need. If you're operating at the raw network level using Network framework, Alamofire really has nothing to do here. Closest Alamofire gets is that you can use the waitsForConnectivity property in URLSessionConfiguration to create a custom Session instance.
I have an application that needs to monitor network changes.
Let's say if Wi-Fi was dropped or reconnected then I need to use some web services.
How can I accomplish this in iOS? I have a captive network that marks users as authenticated after logging in. I want to make sure that the user is authenticated whenever Wi-Fi changes, otherwise I need to perform authentication.
All I want is to perform some HTTP requests on the basis of network changes.
Any help is appreciated. I have tried to use Reachability but that only works when user opens the application.
Reachability allows the app to be notified when the network configuration change.
I used this method:
+ (instancetype)reachabilityForInternetConnection return [self connectivityWithAddress:&zeroAddress];
My apps recieve regular callbacks when I play with the wifi connection.
I'm trying to connect to our push server via MQTT-Client-Framework.
There is no complication for connecting to server and with a few line of code i can connect to server and subscribe to topic.
but I have a few question that I could not find any direct answer for them.
1) How can I keep my client running at background?
2) What happen after device restart? how can I automatically connect to server after device restart?
3)Suppose I got an error during connecting to server. Will this library trying to connect in a loop? how many times it try? or I need to manage this myself?
4) The same 3 scenario for subscribing to topic?
Based on my experience on MQTT-client framework following are the answers to your questions/queries. I hope it clarifies your concerns and helps you to move ahead.
1) How can I keep my client running at background?
You can not keep your MQTT client running in background, as Apple doesn't allow any application to keep running for long time in background. Though if you override its not guaranteed your application will keep running in background. You can read more about background execution support in apple documentation.
Also refer issue posted on github for given framework.
2) What happen after device restart? how can I automatically connect to server after device restart?
Each time your app begin execution you need to connect to your server using MQTT client framework there is no auto connect mechanism available in MQTT-client framework. I suggest to write init your connection in specific controller which executes immediately after your app launch except same as AppDelegate
3) Suppose I got an error during connecting to server. Will this library trying to connect in a loop? how many times it try? or I need to manage this myself?
If your MQTT-client fails to connect your server, you need to handle it yourself, library doesn't try to auto connect as mentioned in previous answer. I have written sample code as below. Use NSTimer for auto connect to server.
[self.mqttSession connectToHost:MQTT_HOST port:MQTT_PORT usingSSL:NO connectHandler:^(NSError *error)
{
if(error)
{
// Application fail to connect to server, write your code to auto connect here
}
}];
4) The same 3 scenario for subscribing to topic?
If your broker server has configuration to track your existing subscription for individual users/client then you don't need to subscribe each time.
Otherwise each time you need to subscribe to same topic on successful connection. Use following MQTTSessionDelegate method to subscribe.
- (void)connected:(MQTTSession *)session
Happy coding :)
1)Project->Capabilities->Background Modes. There has some options for allowing your app to run at background.
2)Generally speaking, MQTT will not be disconnected to the server if your app is allowed to run at background, but i think you would better check up the connection and maybe re-connect MQTT to your server when the app become active again.
AppDelegate-> - (void)applicationDidBecomeActive:(UIApplication *)application;
3)Unfortunately, yes, it will. And you have to manage yourself.
4)I can't help.
For your first question:
Details on how to run in the background on iOS can be found here. This link also lists the actions that Apple allows to run in the background, if your app does not meet those criteria then it is likely to get thrown out of the app store by Apple.
The list also shows which UIBackgroundModes to place in your Info.plist to flag that your app needs background access.
The other 3 I can't help with
We all know that Apple doesn't allow app service to run in the background, so MQTT will be disconnected in the background mode.
Now do one thing use better frameworks for MQTT like this in this framework you will get auto-reconnect and callbacks and many things.
So When you receive a call back that the MQTT is connected, immediately subscribe to all the topics that you have.
And if you want to get all missed messages then you need to change the MQTT configuration to like 'clean = false'.
is there any method to follow the applications on ios devices?
For instance , can I ping to ios devices on server side? or can I send silent push to device to get if application runs or not?
Thank you.
Your best bet is to let the app sending 'online' and 'offline' (combined with some unique per device id to the server) every time it gets open and closed. Then your server can store the state in some kind of database and you can read it from there if an app is currently online or offline on the client device.
I have a project where I need to be able to send messages from a server running a web service to a specific iDevice. I have no idea how to do this, so any help is very appreciated.
The scenario: I have a web service which receives some message from an iDevice (could also be a Mac or PC, even an Android device). Depending on the content of this message I need to be able to send a message from the web service to another iDevice (I know the IP-address of the specific iDevice). I know how to use URLRequests to send a message from an iDevice to a server and collect the response from the server. In principle I could every 10 seconds send a request to the server asking if the server has any new messages to the sender (the iDevice sending the request), but I am pretty sure this is not the correct way to do it. Is there a way to have an iDevice listen for server communication on a specific port, so that the iDevice only does something active when it receives a message from the server to do something, e.g. display a message in the app listening for the server communication?
I guess I need to use something similar to the technology used for iMessage, but how is this done?
I am using XCode 4.6.2, iOS 6.1.
EDIT: Just to clarify my needs a bit more: The APNS seems to be TOO unreliable (at least that is what I have read in other threads regarding APN) as the web service in some cases can have the need for sending 2 distinct message to an iDevice within 1 minute (in some cases seconds), and as far as I have read in other threads this will simply not be possible because of how Apple's server handles ASPNS.
The app i am developing only needs to receive messages from the server when the app is active - is there any way, not using APNs, to do this, e.g. making the app listen for communication on a specific port?
Your scenario seems pretty similar to APPLE PUSH NOTIFICATIONs (APNs).
Ideally your server side should write a code in such a way that if there is any change on server side & need to be informed to all associated devices.
Then your server should post notification Apple server which will then send a notification to all the associated devices.
Refer this link
You already have but can use this code to identify the iOS/Mac deivce
NSString *identifierString = [[NSUserDefaults standardUserDefaults] objectForKey:#"myID"];
if (!identifierString) {
CFUUIDRef identifier = CFUUIDCreate(NULL);
identifierString = (NSString*)CFUUIDCreateString(NULL, identifier);
[[NSUserDefaults standardUserDefaults] setObject:identifierString forKey:#"myID"];
}
NSLog(#"%#",identifierString);
this code works till the lifetime of the app only.
After some search I have decided not to use the APNS, because it seems like people are having all sort of experience with it. I cannot use APNS because my project needs 100 % reliability and instant communication with the server.
I have decided to use tcp communication since my project only will be used in a local network. This will obviously mean more power consumption on the iDevices, but reliability is more crucial to the project.