Zach
Zach

Reputation: 4079

How to reference app code form a SiriIntent extension?

I have setup a SiriKit target within my application recently, but I cannot reference any app code within it.

I have added my app's target to the SiriKit target's Build Targets->Target Dependencies section, but I still get the following errors:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_<CLASSNAME>", referenced from:
      objc-class-ref in IntentHandler.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Where is the name of a app class I am trying to reference in the IntentHandler.m class.

I am able to import the app code class I need to use just fine, but if I try to use it in actual code it results in the error.

Everything "seems" fine with the code too, which is odd. Syntax highlighting works, ctrl+click brings me to the appropriate class, etc, so it's clearly finding the class at some point, just not where it matters most!

My code is like this:

#import "IntentHandler.h"
#import "<CLASSNAME.h>

@interface IntentHandler () <INSearchForPhotosIntentHandling>

@end

@implementation IntentHandler

- (id)handlerForIntent:(INIntent *)intent {
    return self;
}

#pragma mark - INSearchForPhotosIntentHandling
- (void)handleSearchForPhotos:(INSearchForPhotosIntent *)intent completion:(void (^)(INSearchForPhotosIntentResponse *response))completion {
    NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:NSStringFromClass([INSearchForPhotosIntent class])];
    Object test = [[<CLASSNAME> instance] getObjectWithName:@"test"];
    // do stuff with the test Object, which may require me to send the response as INSearchForPhotosIntentResponseCodeFailureRequiringAppLaunch
    // but for now just return INSearchForPhotosIntentResponseCodeContinueInApp.
    INSearchForPhotosIntentResponse *response = [[INSearchForPhotosIntentResponse alloc] initWithCode:INSearchForPhotosIntentResponseCodeContinueInApp userActivity:userActivity];
    completion(response);
}

@end

Upvotes: 2

Views: 1065

Answers (1)

Karthick Selvaraj
Karthick Selvaraj

Reputation: 2505

Here the class Helper.swift can be access from my app and extension. Do as follows.

1.

enter image description here

  1. Go to file inspector in right hand side of Xcode.

enter image description here

  1. My code in extension.

enter image description here

Note: In obj-c you need to do above steps for .h and .m files.

Upvotes: 1

Related Questions