Data is not transferred from iphone to iWatch (AppleWatch) on real devices

I have an iOS app and I programmed the extension for it on appleWatch. I am sending data (NSDictionary) to the appleWatch extension using the transferUserInfo method. Everything works in the simulator, but when I try to run the application on real devices, it seems that iWatch does not receive anything, although the iPhone sends data (I found this reason, I debugged the sender side).

I configured WCSession on both sides. I combined WCSessionDelegate in a class where I should receive data. I use session: didReceiveUserInfo: a method for receiving data in ExtensionDelegate, but still, as I said, everything works fine in the simulator, but nothing is transmitted on real devices.

Does anyone know what the problem is?

here is the code: in the sender side:

inside my class MensaViewController.m

- (void)viewDidLoad
   if ([WCSession isSupported]) {
        session = [WCSession defaultSession];
        session.delegate = self;
        [session activateSession];
   }
   NSLog(@"A dish is being sent");
  [session transferUserInfo:dishDictionary];
}

dishDictionary is declared inside the viewDidLoad method and contains data.

on the receiver side (Watch Extension) I configure WCSession and get the data in ExtensionDelegate.m as follows:

- (void)applicationDidBecomeActive {
    if ([WCSession isSupported]) {
        session = [WCSession defaultSession];
        session.delegate = self;
        [session activateSession];
        NSLog(@"Session activated in iWatch");
    }
}

and I have this method for getting data:

- (void)session:session didReceiveUserInfo:(NSDictionary<NSString *,id> *)userInfo{

    NSLog(@"Received data from the iPhone");

    NSArray<NSString*> *dictionaryKeys = userInfo.allKeys;
    for(int i = 0; i < dictionaryKeys.count; i++){
        Boolean equalsMensaString = [dictionaryKeys[i] isEqualToString:@"beilagen"];
        if(equalsMensaString)
            [self handleTransferredDish:userInfo];

        Boolean equalsNewsString = [dictionaryKeys[i] isEqualToString:@"article"];
        if(equalsNewsString)
            [self handleTransferredNews:userInfo];

        Boolean equalsEventString = [dictionaryKeys[i] isEqualToString:@"description"];
        if(equalsEventString)
            [self handleTransferredEvents:userInfo];

    }
}
+4
source share
2 answers

If you look at the description of the source function, you can see a description of the method that you use to transfer data:

public func transferUserInfo(userInfo: [String : AnyObject]) -> WCSessionUserInfoTransfer

- . -. - , . .

.. , userInfo, .

:

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

-. , replyHandler. , errorHandler . responseHandler, errorHandler , . -. . - , - ( iOS). .

:

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

: , - . , , - , updateApplicationContext transferUserInfo ( updateApplicationContext)

session.sendMessage(messageData, replyHandler: { (replyData) -> Void in
            replyHandler?(replyData)
            }, errorHandler: { (error) -> Void in
                print("error: code:\(error.code) - \(error.localizedDescription)")
                errorHandler?(error)
                 do {
                        try session.updateApplicationContext(messageData)
                    } catch {
                        print("There was an error trying to update watchkit app on the background")
                    }
        })

,

func session(session: WCSession, didReceiveApplicationContext applicationContext: [String : AnyObject])

+2

, , . Apple Watch 2 IPhone 5 6 ( 2 !), , , ( 5-10%). . End!

+1

Source: https://habr.com/ru/post/1627820/


All Articles