WatchOS - complication update from iOS - swift

Is there a way how to update watch complication from iOS app? I've found some solutions but nothing works for me. I need to change the text in the complication to the text inside iOS app whenever I touch my button inside the iOS app. Any solution?

Use the Watch Connectivity framework to send the update to the watch by calling your WCSession object’s transferCurrentComplicationUserInfo: method. This method sends a high priority message to your WatchKit extension, waking it as needed to deliver the data. As soon as the watch receives the data, it calls your session delegate’s session:didReceiveUserInfo: method. In this method, update your complication data using the provided user info dictionary, and then call your data source’s reloadTimelineForComplication: or extendTimelineForComplication: method to update your timeline.
From here
More details in this 2016 WWDC session.
But pay attention that number of such pushes is limited to 50 in watchOS3.

Related

Refresh watchos app based on internet connectivity

I have found a great description of the process for refreshing both the watchapp UI and its complications here. That works for me, even though sometimes the UI is only updated when I actually bring the app to the foreground (but that's another issue).
what I have been doing so far is this:
1 - I schedule a background refresh;
2 - When the background refresh task is called, I schedule a background downloadTask;
3 - After completion, the downloadTask call its delegate method (didFinishDownloadingTo), where I call another method to update the UI, reload my complications with new data and to schedule a snapshot refresh and another background refresh.
This is almost working fine (with the ocasional problem I mentioned above). But I put my watch on flight mode sometimes. What happens here is that the error delegate method is called, and so I schedule another app refresh for about 1 hour. If still in flight mode, it will request another refresh in one hour, and so on.
The problem with this approach is that when I turn off the flight mode, the app takes a long time to update its UI, depending on when the next update is scheduled.
Can someone suggest a better approach to get new data as soon as one gets internet connectivity back?
At the moment (watchOS 3.2) there is no framework in watchOS that could tell you when the device connects to the internet. However, you could leverage the Reachability framework in your iOS app and use the WatchConnectivity framework to signal your Watch app when it can refresh its UI.

What communication to use, updateApplicationContext or sendMessage for constant data sync

I have an iOS shopping list app, where items are added and displayed in a tableView. I want to create a Watch App Extension but I’m thinking of what is the best function call to use in this case, the updateApplicationContext(:) method or the sendMessage(:replyHandler:errorHandler:) method I was reading the documentation but I’m a little confused since both seem to work.
Here is the functionality I’m expecting to have…
What I want is to be able to add items in the iOS app even if the Watch app is Off, which is normal behavior, BUT I want the Watch app to update with whatever is in the tableView (in iOS) as soon as it is turned on and even if the iPhone is not On at the time the Watch is turned on.
In other words, I want the data in the iOS app to always be in sync with the Watch app.
Which is the best function call to use in this case, the updateApplicationContext(_:) method or the sendMessage(_:replyHandler:errorHandler:) method?
Thanks
As for me, I would use updateApplicationContext(_:) since you would want to update it in real time or in the background as it gets connected.
as for this sendMessage(_:replyHandler:errorHandler:) The cons is The isReachable property must currently be true for these methods to succeed. so you might get a slight delay to update your UI until it is reachable and ask for updates.

Apple Watch and iphone communication

I am implementing apple watch app with in my existing app.I need to full fill these task between both iphone and watch
1) sending data from watch to iphone Done (by using openParentApplication).
2) getting call back also done (using openParentApplication call back method)
3) I need to get apple watch notify when user click on a button on iphone app .I have implemented reverse functionality using openParentApplication.
I stuck how to update apple watch UI after user click on any button or any particular task happen on iphone app.
Please let me know is there any way to perform passing event and data from iphone to apple watch
Please use this link https://github.com/mutualmobile/MMWormhole for communication between iphone and watchKit.
You should checkout the new WCSessionDelegate is watchOS 2.0. It can be implemented on both the Apple Watch and contains multiple methods for sending data back and forth between the two devices. Detailed information can be found in the WWDC video Introducing Watch Connectivity

iphone: notification when receiving a call?

I'm developing for a jailbroken device, and I want to create an app that detects a phone call, and presents an alert on top of the call screen. How can I achieve this? What hidden frameworks should I use?
Within CoreTelephony is the CTCallCenter class which includes the callEventHandler property, which is a block that runs upon changes in the call state. As described in the documentation, you could use this to become notified of these states:
CTCallStateDialing;
CTCallStateIncoming;
CTCallStateConnected;
CTCallStateDisconnected;
Docs say you must be in active app state. If you are suspended, then you only get one block state change notification upon waking up. If you are jailbroken and in background state, hopefully you would get your block executed, so you could become aware of this.

Iphone App - Is it possible to use text from an app?

Hey, I am about to start working on an app. I am a beginner, so I am starting out with a pretty basic concept. But, I was wondering if it was possible to send texts from an app. For example, if the person using my app sets a new high score, could they hit a publish button and my app could then send a text to his buddy bragging about the new high score.
Also, what if someone is using my app and they receive a text, does the OS take over, or do I have to handle the reception of text/calls. Is it possible to alter the way the phone behaves when my app is disrupted by calls/texts.
Thanks for any advice you can give. Have a good Monday everyone!
Apple's iOS documentation has a section that roughly covers how to incorporate in-app SMS.
Basically, your application displays an MFMessageComposeViewController as a modal view controller. It won't cause your app to terminate or background — it just lets your user send a text message, and when done, return to your app and continue.
When a phone call, text message or another notification comes in, your application delegate's applicationWillResignActive: method is called. It's up to you what you want your app to do while the user is dealing with the call, message or notification. If the call is declined or the alert dismissed, your application delegate's applicationDidBecomeActive: method is called and your application can resume as if nothing happened. Otherwise, the app either exits or backgrounds (depending on whether you want it to support multitasking), and you'll also have to handle it from there.
Also bear in mind what Toastor says about
Controlling whether messages can display to your user or not
Bills related to texting plans
There is no way to change the way the phone responds to calls. The only way to prevent your app from being interrupted by an incoming call is by activating the airplane mode on the device - which you cannot enforce from within the app.
Same goes for incoming texts - there is no way to notify your app if a message has been received. How would the system know if the message is meant for your app anyway?
The only thing you can actually do is send a text message from within your app. But if I were you I'd go either with established leaderboards or the new GameKit (have not checked this out yet myself, though).
Or, at least, use mail instead of text messages, since texts are not free in every country.