Assistance with WatchConnectivity - Objective-c

Viewed 1635

I have been attempting to add a WatchKit target to an existing app written in Objc and have been completely unable to get the messaging working. When I run the extension, start the session, and check for reachability everything is fine, I am showing the container app is reachable from the extension. However, when I send a message, the phone application does not wake up. From all of the documentation and samples that I have seen, the phone application should run in the background, however, this is not happening. Am I missing something? Any help would be appreciated.

Attached is the associated code:

From the InterfaceController.m of the extension, I am calling:

[[WCSession defaultSession] sendMessage:@{@"message":@"begin"} replyHandler:nil errorHandler:nil];

ExtensionDelegate.h

#import <WatchKit/WatchKit.h>
#import <WatchConnectivity/WatchConnectivity.h>

@interface ExtensionDelegate : NSObject <WKExtensionDelegate,WCSessionDelegate>

@end

ExtensionDelegate.m

- (void)applicationDidFinishLaunching {
    // Perform any final initialization of your application.
    if ([WCSession isSupported]) {
        WCSession *session = [WCSession defaultSession];
        session = [WCSession defaultSession];
        session.delegate = self;
        [session activateSession];
        if (session.isReachable) {
            NSLog(@"Able to reach app.");
    }
   }
}

IOS AppDelegate.h

#import <UIKit/UIKit.h>
#import "objShoppingList.h"
#import "databaseController.h"
#import <WatchConnectivity/WatchConnectivity.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@end

IOS AppDelegate.m

#import "AppDelegate.h"
@import CoreLocation;
@interface AppDelegate ()<CLLocationManagerDelegate, WCSessionDelegate>{
    CLLocationManager *locationManager;
    WCSession *session;
}
@end
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.
    if ([WCSession isSupported]) {
        [WCSession defaultSession].delegate = self;
        session = [WCSession defaultSession];
        session.delegate = self;
        NSLog(@"Sessiopn on phone starting");
        [[WCSession defaultSession] activateSession];
    }
    NSLog(@"iphone app starting");

 . . .
   return YES;
}
- (void)session:(nonnull WCSession *)session didReceiveMessage:(nonnull NSDictionary<NSString *,id> *)message replyHandler:(nonnull void (^)(NSDictionary<NSString *,id> * __nonnull))replyHandler {

    // In this case, the message content being sent from the app is a simple begin message. This tells the app to wake up and begin sending location information to the watch.
    NSLog(@"Reached IOS APP");
}
-(void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *,id> *)message{
    NSLog(@"Reached IOS APP");
}

@end

Every test that is done, the IOS app does not start, and I do not receive the NSLog message from didFinishLaunchingWithOptions

Any help would be greatly appreciated.

0 Answers
Related