代码之家  ›  专栏  ›  技术社区  ›  Kishore Kumar

添加扩展后,我得到词法和预处理器错误Xcode 9.3?

  •  0
  • Kishore Kumar  · 技术社区  · 8 年前

    大家好,我已经正确添加了通知服务扩展和目标。当我构建项目时,我遇到了词法错误。

    尝试清理归档文件,重新启动Xcode,更改框架路径。

    如果我删除了通知服务扩展,那么一切都正常,当我将通知扩展添加到我的项目中时,我遇到了这个错误。

    如果有人越过这个问题。让我知道我做错了什么。

    enter image description here

    我做了什么?

    文件->新建->目标->在项目下添加了通知服务扩展。

    对扩展类文件进行了更改。

    self.contentHandler = contentHandler;
        self.bestAttemptContent = [request.content mutableCopy];
        NSString *imgUrl = request.content.userInfo[@"data"][@"attachment-url"];
        NSURL *imageURL = [NSURL URLWithString:imgUrl];
        NSError *error;
        UNNotificationAttachment *icon = [UNNotificationAttachment attachmentWithIdentifier:@"image" URL:imageURL options:nil error:&error];
        if (error)
        {
            NSLog(@"error while storing image attachment in notification: %@", error);
        }
        if (icon)
        {
            self.bestAttemptContent.attachments = @[icon];
        }
        self.contentHandler(self.bestAttemptContent);
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   Teja Nandamuri    8 年前

    如果您使用的是cocoa吊舱,请编辑您的吊舱文件,并创建两种类型的吊舱,一种用于主目标应用程序,另一种用于扩展目标。

    def application_pods
    use_frameworks!
    #list of frameworks you use in your main target
    pod 'UIImageView+WebCache'
    end
    
    
    def extension_pods
    use_frameworks!
    #list of frameworks you would use in your extension
    pod 'UIImageView+WebCache'    
    end
    
    
    target 'YourMainTargetName' do
    # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
    # Pods for YourTargetName
    application_pods
    end
    
    target 'NotificationService' do
    extension_pods
    end
    

    如果不使用pods,则需要选择UIImageView+网络缓存。H在目标成员资格部分,您需要选中扩展目标复选框。

        2
  •  0
  •   Kishore Kumar    7 年前

    最后:

    问题是因为创建的扩展名将头路径作为父文件头路径,因此,如果您在前缀中提到任何pod文件头路径,那么它将给出错误,因此请删除头路径并将其保留为空。

    生成设置->标题路径->将其移除。

    确保在删除路径时选择了扩展目标。

    推荐文章