【问题标题】:How to reference app code form a SiriIntent extension?如何从 SiriIntent 扩展中引用应用程序代码?
【发布时间】:2016-11-09 06:59:52
【问题描述】:

我最近在我的应用程序中设置了一个 SiriKit 目标,但我无法在其中引用任何应用程序代码。

我已将我的应用程序的目标添加到 SiriKit 目标的 Build Targets->Target Dependencies 部分,但我仍然收到以下错误:

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)

我试图在 IntentHandler.m 类中引用的应用程序类的名称在哪里。

我可以导入我需要使用的应用程序代码类,但如果我尝试在实际代码中使用它会导致错误。

代码的一切“似乎”都很好,这很奇怪。语法突出显示有效,ctrl+click 将我带到适当的类等,因此很明显在某些时候找到了类,而不是最重要的地方!

我的代码是这样的:

#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

【问题讨论】:

    标签: ios xcode sirikit ios-targets


    【解决方案1】:

    Helper.swift 类可以从 my appextension 访问。执行以下操作。

    1.

    1. 转到 Xcode 右侧的文件检查器。

    1. 我的代码在扩展中。

    注意:在 obj-c 中,您需要对 .h 和 .m 文件执行上述步骤。

    【讨论】:

    • 大概这意味着 Helper.swift 文件使用的任何依赖项也必须包含到 SiriKitDemoExtension 目标中,对吧?是否将 SiriKitDemo 作为目标依赖项包含该目标中包含的所有文件?
    • 是的,我们需要将Helper.swift的依赖文件添加到sirikitDemoExtension目标中,否则会报错。
    猜你喜欢
    • 2018-10-14
    • 2019-10-08
    • 1970-01-01
    • 2014-12-08
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 2015-05-23
    • 2016-08-22
    相关资源
    最近更新 更多