errorHandler: NO with WCErrorCodeDeliveryFailed - not sure where I am going wrong
I'm trying to send the UUID string of the phone to the watch once the connection is made (no action is required from the user). I've used this tutorial (https://medium.com/@vanessaforney/ios-development-watch-connectivity-32415d415854) but I keep getting "WCSession _onqueue_notifyOfMessageError:messageID:withErrorHandler:] 21FB4ABE-D177-4689-AF50-62759283112C errorHandler: NO with WCErrorCodeDeliveryFailed" error. I'm not sure what I'm doing wrong. Apologies in advance, I would have put up an MCVE/SSCCE example but I wasn't sure how it would work with this. Any help would be very appreciated!
This is the WatchSessionManager on the ios app side:
class WatchSessionManager: NSObject, WCSessionDelegate {
static let sharedManager = WatchSessionManager()
var device_id = ""
private override init() {
super.init()
session?.delegate = self
session?.activate()
}
func setDeviceID(id: String) {
device_id = id
}
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
private var validSession: WCSession? {
if let session = session, session.isPaired && session.isWatchAppInstalled{
os_log("paired and reachable")
return session
}
return nil
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
os_log("activationdidcompletewith")
updateApplicationContext()
}
func sessionDidBecomeInactive(_ session: WCSession) {
}
func sessionDidDeactivate(_ session: WCSession) {
}
func startSession() {
session?.delegate = self
session?.activate()
updateApplicationContext()
}
func updateApplicationContext() {
let context = ["device_id" : device_id]
do {
Swift.print("trying to update application context")
try WatchSessionManager.sharedManager.updateApplicationContext(applicationContext: context)
} catch {
Swift.print("error updating application context")
}
}
}
// Application Context
extension WatchSessionManager {
func updateApplicationContext(applicationContext: [String : Any]) throws{
if let session = validReachableSession {
do {
os_log("actually updating context")
try session.updateApplicationContext(applicationContext)
} catch let error {
throw error
}
}
}
}
extension WatchSessionManager {
// Sender
private var validReachableSession: WCSession? {
if let session = validSession, session.isReachable {
return session
}
return nil
}
// Receiver
func session(session: WCSession, didReceiveMessage message: [String : Any],
replyHandler: ([String : Any]) -> Void, errorHandler: ((Error) -> Void)? = nil) {
os_log("receiver")
if message["device_id"] != nil {
updateApplicationContext()
}
}
}
Then in my AppDelegate.swift, I have included:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
WatchSessionManager.sharedManager.startSession()
WatchSessionManager.sharedManager.updateApplicationContext()
return true
}
And this is my PhoneSessionManager on the watch side:
import WatchConnectivity
import os.log
class PhoneSessionManager: NSObject, WCSessionDelegate {
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
requestApplicationContext()
}
static let sharedManager = PhoneSessionManager()
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
func startSession() {
session?.delegate = self
session?.activate()
}
func requestApplicationContext() {
sendMessage(message: ["device_id": true as AnyObject], replyHandler: nil, errorHandler: nil)
}
func sessionReachabilityDidChange(_ session: WCSession) {
requestApplicationContext()
}
}
extension PhoneSessionManager {
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
DispatchQueue.main.async(execute: {
UserSummary.userSummary.updateFromContext(applicationContext: applicationContext)
})
}
}
extension PhoneSessionManager {
private var validReachableSession: WCSession? {
if let session = session, session.isReachable {
return session
}
return nil
}
func sendMessage(message: [String : Any],replyHandler: (([String : Any]) -> Void)? = nil, errorHandler: ((Error) -> Void)? = nil) {
validReachableSession?.sendMessage(message, replyHandler: replyHandler, errorHandler: errorHandler)
}
}
Then in my ExtensionDelegate.swift I have:
import WatchKit
class ExtensionDelegate: NSObject, WKExtensionDelegate {
override init() {
super.init()
PhoneSessionManager.sharedManager.startSession()
}
func applicationDidFinishLaunching() {
PhoneSessionManager.sharedManager.requestApplicationContext()
// Perform any final initialization of your application.
}
}
ios swift watchkit watch-os watchconnectivity
add a comment |
I'm trying to send the UUID string of the phone to the watch once the connection is made (no action is required from the user). I've used this tutorial (https://medium.com/@vanessaforney/ios-development-watch-connectivity-32415d415854) but I keep getting "WCSession _onqueue_notifyOfMessageError:messageID:withErrorHandler:] 21FB4ABE-D177-4689-AF50-62759283112C errorHandler: NO with WCErrorCodeDeliveryFailed" error. I'm not sure what I'm doing wrong. Apologies in advance, I would have put up an MCVE/SSCCE example but I wasn't sure how it would work with this. Any help would be very appreciated!
This is the WatchSessionManager on the ios app side:
class WatchSessionManager: NSObject, WCSessionDelegate {
static let sharedManager = WatchSessionManager()
var device_id = ""
private override init() {
super.init()
session?.delegate = self
session?.activate()
}
func setDeviceID(id: String) {
device_id = id
}
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
private var validSession: WCSession? {
if let session = session, session.isPaired && session.isWatchAppInstalled{
os_log("paired and reachable")
return session
}
return nil
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
os_log("activationdidcompletewith")
updateApplicationContext()
}
func sessionDidBecomeInactive(_ session: WCSession) {
}
func sessionDidDeactivate(_ session: WCSession) {
}
func startSession() {
session?.delegate = self
session?.activate()
updateApplicationContext()
}
func updateApplicationContext() {
let context = ["device_id" : device_id]
do {
Swift.print("trying to update application context")
try WatchSessionManager.sharedManager.updateApplicationContext(applicationContext: context)
} catch {
Swift.print("error updating application context")
}
}
}
// Application Context
extension WatchSessionManager {
func updateApplicationContext(applicationContext: [String : Any]) throws{
if let session = validReachableSession {
do {
os_log("actually updating context")
try session.updateApplicationContext(applicationContext)
} catch let error {
throw error
}
}
}
}
extension WatchSessionManager {
// Sender
private var validReachableSession: WCSession? {
if let session = validSession, session.isReachable {
return session
}
return nil
}
// Receiver
func session(session: WCSession, didReceiveMessage message: [String : Any],
replyHandler: ([String : Any]) -> Void, errorHandler: ((Error) -> Void)? = nil) {
os_log("receiver")
if message["device_id"] != nil {
updateApplicationContext()
}
}
}
Then in my AppDelegate.swift, I have included:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
WatchSessionManager.sharedManager.startSession()
WatchSessionManager.sharedManager.updateApplicationContext()
return true
}
And this is my PhoneSessionManager on the watch side:
import WatchConnectivity
import os.log
class PhoneSessionManager: NSObject, WCSessionDelegate {
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
requestApplicationContext()
}
static let sharedManager = PhoneSessionManager()
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
func startSession() {
session?.delegate = self
session?.activate()
}
func requestApplicationContext() {
sendMessage(message: ["device_id": true as AnyObject], replyHandler: nil, errorHandler: nil)
}
func sessionReachabilityDidChange(_ session: WCSession) {
requestApplicationContext()
}
}
extension PhoneSessionManager {
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
DispatchQueue.main.async(execute: {
UserSummary.userSummary.updateFromContext(applicationContext: applicationContext)
})
}
}
extension PhoneSessionManager {
private var validReachableSession: WCSession? {
if let session = session, session.isReachable {
return session
}
return nil
}
func sendMessage(message: [String : Any],replyHandler: (([String : Any]) -> Void)? = nil, errorHandler: ((Error) -> Void)? = nil) {
validReachableSession?.sendMessage(message, replyHandler: replyHandler, errorHandler: errorHandler)
}
}
Then in my ExtensionDelegate.swift I have:
import WatchKit
class ExtensionDelegate: NSObject, WKExtensionDelegate {
override init() {
super.init()
PhoneSessionManager.sharedManager.startSession()
}
func applicationDidFinishLaunching() {
PhoneSessionManager.sharedManager.requestApplicationContext()
// Perform any final initialization of your application.
}
}
ios swift watchkit watch-os watchconnectivity
add a comment |
I'm trying to send the UUID string of the phone to the watch once the connection is made (no action is required from the user). I've used this tutorial (https://medium.com/@vanessaforney/ios-development-watch-connectivity-32415d415854) but I keep getting "WCSession _onqueue_notifyOfMessageError:messageID:withErrorHandler:] 21FB4ABE-D177-4689-AF50-62759283112C errorHandler: NO with WCErrorCodeDeliveryFailed" error. I'm not sure what I'm doing wrong. Apologies in advance, I would have put up an MCVE/SSCCE example but I wasn't sure how it would work with this. Any help would be very appreciated!
This is the WatchSessionManager on the ios app side:
class WatchSessionManager: NSObject, WCSessionDelegate {
static let sharedManager = WatchSessionManager()
var device_id = ""
private override init() {
super.init()
session?.delegate = self
session?.activate()
}
func setDeviceID(id: String) {
device_id = id
}
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
private var validSession: WCSession? {
if let session = session, session.isPaired && session.isWatchAppInstalled{
os_log("paired and reachable")
return session
}
return nil
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
os_log("activationdidcompletewith")
updateApplicationContext()
}
func sessionDidBecomeInactive(_ session: WCSession) {
}
func sessionDidDeactivate(_ session: WCSession) {
}
func startSession() {
session?.delegate = self
session?.activate()
updateApplicationContext()
}
func updateApplicationContext() {
let context = ["device_id" : device_id]
do {
Swift.print("trying to update application context")
try WatchSessionManager.sharedManager.updateApplicationContext(applicationContext: context)
} catch {
Swift.print("error updating application context")
}
}
}
// Application Context
extension WatchSessionManager {
func updateApplicationContext(applicationContext: [String : Any]) throws{
if let session = validReachableSession {
do {
os_log("actually updating context")
try session.updateApplicationContext(applicationContext)
} catch let error {
throw error
}
}
}
}
extension WatchSessionManager {
// Sender
private var validReachableSession: WCSession? {
if let session = validSession, session.isReachable {
return session
}
return nil
}
// Receiver
func session(session: WCSession, didReceiveMessage message: [String : Any],
replyHandler: ([String : Any]) -> Void, errorHandler: ((Error) -> Void)? = nil) {
os_log("receiver")
if message["device_id"] != nil {
updateApplicationContext()
}
}
}
Then in my AppDelegate.swift, I have included:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
WatchSessionManager.sharedManager.startSession()
WatchSessionManager.sharedManager.updateApplicationContext()
return true
}
And this is my PhoneSessionManager on the watch side:
import WatchConnectivity
import os.log
class PhoneSessionManager: NSObject, WCSessionDelegate {
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
requestApplicationContext()
}
static let sharedManager = PhoneSessionManager()
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
func startSession() {
session?.delegate = self
session?.activate()
}
func requestApplicationContext() {
sendMessage(message: ["device_id": true as AnyObject], replyHandler: nil, errorHandler: nil)
}
func sessionReachabilityDidChange(_ session: WCSession) {
requestApplicationContext()
}
}
extension PhoneSessionManager {
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
DispatchQueue.main.async(execute: {
UserSummary.userSummary.updateFromContext(applicationContext: applicationContext)
})
}
}
extension PhoneSessionManager {
private var validReachableSession: WCSession? {
if let session = session, session.isReachable {
return session
}
return nil
}
func sendMessage(message: [String : Any],replyHandler: (([String : Any]) -> Void)? = nil, errorHandler: ((Error) -> Void)? = nil) {
validReachableSession?.sendMessage(message, replyHandler: replyHandler, errorHandler: errorHandler)
}
}
Then in my ExtensionDelegate.swift I have:
import WatchKit
class ExtensionDelegate: NSObject, WKExtensionDelegate {
override init() {
super.init()
PhoneSessionManager.sharedManager.startSession()
}
func applicationDidFinishLaunching() {
PhoneSessionManager.sharedManager.requestApplicationContext()
// Perform any final initialization of your application.
}
}
ios swift watchkit watch-os watchconnectivity
I'm trying to send the UUID string of the phone to the watch once the connection is made (no action is required from the user). I've used this tutorial (https://medium.com/@vanessaforney/ios-development-watch-connectivity-32415d415854) but I keep getting "WCSession _onqueue_notifyOfMessageError:messageID:withErrorHandler:] 21FB4ABE-D177-4689-AF50-62759283112C errorHandler: NO with WCErrorCodeDeliveryFailed" error. I'm not sure what I'm doing wrong. Apologies in advance, I would have put up an MCVE/SSCCE example but I wasn't sure how it would work with this. Any help would be very appreciated!
This is the WatchSessionManager on the ios app side:
class WatchSessionManager: NSObject, WCSessionDelegate {
static let sharedManager = WatchSessionManager()
var device_id = ""
private override init() {
super.init()
session?.delegate = self
session?.activate()
}
func setDeviceID(id: String) {
device_id = id
}
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
private var validSession: WCSession? {
if let session = session, session.isPaired && session.isWatchAppInstalled{
os_log("paired and reachable")
return session
}
return nil
}
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
os_log("activationdidcompletewith")
updateApplicationContext()
}
func sessionDidBecomeInactive(_ session: WCSession) {
}
func sessionDidDeactivate(_ session: WCSession) {
}
func startSession() {
session?.delegate = self
session?.activate()
updateApplicationContext()
}
func updateApplicationContext() {
let context = ["device_id" : device_id]
do {
Swift.print("trying to update application context")
try WatchSessionManager.sharedManager.updateApplicationContext(applicationContext: context)
} catch {
Swift.print("error updating application context")
}
}
}
// Application Context
extension WatchSessionManager {
func updateApplicationContext(applicationContext: [String : Any]) throws{
if let session = validReachableSession {
do {
os_log("actually updating context")
try session.updateApplicationContext(applicationContext)
} catch let error {
throw error
}
}
}
}
extension WatchSessionManager {
// Sender
private var validReachableSession: WCSession? {
if let session = validSession, session.isReachable {
return session
}
return nil
}
// Receiver
func session(session: WCSession, didReceiveMessage message: [String : Any],
replyHandler: ([String : Any]) -> Void, errorHandler: ((Error) -> Void)? = nil) {
os_log("receiver")
if message["device_id"] != nil {
updateApplicationContext()
}
}
}
Then in my AppDelegate.swift, I have included:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
WatchSessionManager.sharedManager.startSession()
WatchSessionManager.sharedManager.updateApplicationContext()
return true
}
And this is my PhoneSessionManager on the watch side:
import WatchConnectivity
import os.log
class PhoneSessionManager: NSObject, WCSessionDelegate {
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
requestApplicationContext()
}
static let sharedManager = PhoneSessionManager()
private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil
func startSession() {
session?.delegate = self
session?.activate()
}
func requestApplicationContext() {
sendMessage(message: ["device_id": true as AnyObject], replyHandler: nil, errorHandler: nil)
}
func sessionReachabilityDidChange(_ session: WCSession) {
requestApplicationContext()
}
}
extension PhoneSessionManager {
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
DispatchQueue.main.async(execute: {
UserSummary.userSummary.updateFromContext(applicationContext: applicationContext)
})
}
}
extension PhoneSessionManager {
private var validReachableSession: WCSession? {
if let session = session, session.isReachable {
return session
}
return nil
}
func sendMessage(message: [String : Any],replyHandler: (([String : Any]) -> Void)? = nil, errorHandler: ((Error) -> Void)? = nil) {
validReachableSession?.sendMessage(message, replyHandler: replyHandler, errorHandler: errorHandler)
}
}
Then in my ExtensionDelegate.swift I have:
import WatchKit
class ExtensionDelegate: NSObject, WKExtensionDelegate {
override init() {
super.init()
PhoneSessionManager.sharedManager.startSession()
}
func applicationDidFinishLaunching() {
PhoneSessionManager.sharedManager.requestApplicationContext()
// Perform any final initialization of your application.
}
}
ios swift watchkit watch-os watchconnectivity
ios swift watchkit watch-os watchconnectivity
edited Nov 19 '18 at 22:10
jaewhyun
asked Nov 19 '18 at 21:49
jaewhyunjaewhyun
2618
2618
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I've had this error when trying to send an integer array using the send message function. I suggest you try sendMessage(message: ["device_id": "test"], replyHandler: nil, errorHandler: nil) instead of sending true as AnyObject. If that works for you try sending true as a boolean instead of AnyObject.
Hi, I tried that but it's still giving me the same error :(
– jaewhyun
Nov 20 '18 at 3:23
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383132%2ferrorhandler-no-with-wcerrorcodedeliveryfailed-not-sure-where-i-am-going-wron%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've had this error when trying to send an integer array using the send message function. I suggest you try sendMessage(message: ["device_id": "test"], replyHandler: nil, errorHandler: nil) instead of sending true as AnyObject. If that works for you try sending true as a boolean instead of AnyObject.
Hi, I tried that but it's still giving me the same error :(
– jaewhyun
Nov 20 '18 at 3:23
add a comment |
I've had this error when trying to send an integer array using the send message function. I suggest you try sendMessage(message: ["device_id": "test"], replyHandler: nil, errorHandler: nil) instead of sending true as AnyObject. If that works for you try sending true as a boolean instead of AnyObject.
Hi, I tried that but it's still giving me the same error :(
– jaewhyun
Nov 20 '18 at 3:23
add a comment |
I've had this error when trying to send an integer array using the send message function. I suggest you try sendMessage(message: ["device_id": "test"], replyHandler: nil, errorHandler: nil) instead of sending true as AnyObject. If that works for you try sending true as a boolean instead of AnyObject.
I've had this error when trying to send an integer array using the send message function. I suggest you try sendMessage(message: ["device_id": "test"], replyHandler: nil, errorHandler: nil) instead of sending true as AnyObject. If that works for you try sending true as a boolean instead of AnyObject.
answered Nov 19 '18 at 23:18
MykMyk
906
906
Hi, I tried that but it's still giving me the same error :(
– jaewhyun
Nov 20 '18 at 3:23
add a comment |
Hi, I tried that but it's still giving me the same error :(
– jaewhyun
Nov 20 '18 at 3:23
Hi, I tried that but it's still giving me the same error :(
– jaewhyun
Nov 20 '18 at 3:23
Hi, I tried that but it's still giving me the same error :(
– jaewhyun
Nov 20 '18 at 3:23
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383132%2ferrorhandler-no-with-wcerrorcodedeliveryfailed-not-sure-where-i-am-going-wron%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown