Thanks for your response Claude31,Did you use the method transferUserInfo from iOS to AppWatch ?I did run both targets for watch app and then for iOS App. And from iOS app (ViewController) and I can still send message to WatchApp (InterfaceController) with this wcSession.updateApplicationContext(message), but the other method wcSession.transferUserInfo(data) does not worked. This is just a testing prototype, in my main app we use heavily data on transferUserInfo so I need to figure out the issue with breaking transferUserInfo
Post
Replies
Boosts
Views
Activity
Yes, I try adding the sendMessage at the same place, and it works, that strange, same code run in Xcode 10 works in both cases. if wcSession.isReachable { let data = ["text": "User info from the iphone"] wcSession.transferUserInfo(data) // --> WatchKit does not receive this let message = ["TestID": "send Message from the iphone"] wcSession.sendMessage(message, replyHandler: nil) // --> WatchKit receive this }Look like I need to migrate to use sendMessage instead since we cannot deploy with Xcode 10 from April 2020
I have same issue, do we have any updates/work around for this issue ?
I already implement with singleton WKProcessPool and pass here when initialize this WKWebviewViewController. Here is a sample logic I used to check the cookies from an website url after it finishes the navigation, cookies does not there
import UIKit
import WebKit
class WKWebviewViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
var urlToLoad: String = "<any website url, I even try with apple.com>"
var cookiesTxt: String!
var processPool: WKProcessPool!
var wkWebviewconfigure: WKWebViewConfiguration = WKWebViewConfiguration()
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// webView programatically
let bounds = self.view.bounds
let frame = CGRect(x: bounds.origin.x, y: bounds.origin.y + 100, width: bounds.width, height: bounds.height)
wkWebviewconfigure.processPool = processPool
self.webView = WKWebView(frame: frame, configuration: wkWebviewconfigure)
self.view.addSubview(self.webView)
webView.navigationDelegate = self
webView.uiDelegate = self
if let url = URL(string: urlToLoad) {
let request = URLRequest(url: url)
DispatchQueue.main.async {
self.webView.load(request)
}
}
}
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let httpCookieStore = webView.configuration.websiteDataStore.httpCookieStore
httpCookieStore.getAllCookies { (cookies) in
print(cookies) // <--- not getting all the cookies most of time here, but sometime it works
}
}
}
After a week struggling, I found a way to make it work. Posting here in case anyone need.
#1 Have an instance of processPool and wesiteDataStore.nonpersistent() (make them a global variables if you want to get the Cookies outside of webview didFinish navigation of the same wkWebview)
#2 Create an instance of wkWebviewconfigure with these two:
var wkWebviewconfigure: WKWebViewConfiguration = WKWebViewConfiguration()
wkWebviewconfigure.processPool = myProcessPool
wkWebviewconfigure.websiteDatastore = myWebsiteDatastore // <--- have to be nonpersistent type
#3 Generate webview from code with this wkWebviewconfigure, assigning wkWebviewconfigure to your wkWebview.configuration from .xib and storyboard will not work