Call a public method of a WKInterfaceController from ExtensionDelegate class- WatchKit

394 views Asked by At

I am calling the

`[[WCSession defaultSession] updateApplicationContext:message error:error]` 

method which is triggered in my

 `-(void)session:(WCSession *)session didReceiveApplicationContext:(NSDictionary<NSString *,id> *)applicationContext`

method in ExtensionDelegate. But from here I want to call a public method in a WKInterfaceController to update my UI. I don't want to reload the root controllers as this particular controller is not the root controller. Is it possible to call any public method from ExtensionDelegate. Can I call

-(void)session:(WCSession *)session didReceiveApplicationContext:(NSDictionary<NSString *,id> *)applicationContext

from somewhere within Interface controller instead of ExtensionDelegate?

1

There are 1 answers

1
Akhilrajtr On

You can use WCSession's

public func sendMessage(message: [String : AnyObject], replyHandler: (([String : AnyObject]) -> Void)?, errorHandler: ((NSError) -> Void)?) 

this will invoke WCSessionDelegate's

public func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void)

method in delegate class. This can be used from both app and extension for instantaneous message transfer. Read more