0

我正在尝试将新版本的 ATInternet 的ATTracker(现在用Swift制作)绑定到Xamarin.Forms项目。

我遵循本教程并从这个项目示例开始。我用 ATInternet 库替换了本机参考。然后,我在 Mac 上使用 Sharpie 生成了ApiDefinition.cs文件(并将其简化为最小版本,因此它只能初始化默认跟踪器)。我得到以下ApiDefinition.cs文件:

//// @interface ATInternet : NSObject
[BaseType(typeof(NSObject))]
//[DisableDefaultCtor]
public interface ATInternet
{
    // @property (readonly, nonatomic, strong) Tracker * _Nonnull defaultTracker;
    [Export("defaultTracker", ArgumentSemantic.Strong)]
    Tracker DefaultTracker { get; }

    // @property (readonly, nonatomic, strong, class) ATInternet * _Nonnull sharedInstance;
    [Static]
    [Export("sharedInstance")]
    ATInternet SharedInstance();

    // -(Tracker * _Nonnull)tracker:(NSString * _Nonnull)name __attribute__((warn_unused_result));
    [Export("tracker:")]
    Tracker Tracker(string name);
}

// @interface Tracker : NSObject
[BaseType(typeof(NSObject))]
public interface Tracker
{
    // -(void)setConfig:(NSDictionary<NSString *,NSString *> * _Nonnull)configuration override:(BOOL)override sync:(BOOL)sync completionHandler:(void (^ _Nullable)(BOOL))completionHandler;
    [Export("setConfig:override:sync:completionHandler:")]
    void SetConfig(NSDictionary<NSString, NSString> configuration, bool @override, bool sync, [NullAllowed] Action<bool> completionHandler);
}

然后在我的 Xamarin.iOS 项目中像这样使用它:

public partial class ViewController : UIViewController
{
    protected ViewController(IntPtr handle) : base(handle) {}

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var instance = XamarinBindingLibrary.ATInternet.SharedInstance();
        //var tracker = instance.DefaultTracker;
    }
}

但是每次我尝试编译项目时,都会出现以下错误:

2>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++  -framework Foundation -framework QuartzCore -framework CloudKit -framework UIKit -framework CoreGraphics -F /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/obj/iPhoneSimulator/Debug/mtouch-cache -framework Tracker -F /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/obj/iPhoneSimulator/Debug/mtouch-cache -framework TrackerExtension -weak_framework Intents -weak_framework CFNetwork -Xlinker -rpath -Xlinker @executable_path/Frameworks /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/obj/iPhoneSimulator/Debug/mtouch-cache/x86_64/main.o /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libmonosgen-2.0.a /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libxamarin-debug.a -force_load /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libapp.a -Wl,-pie -arch x86_64 -gdwarf-2 -std=c99 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.2.sdk -Qunused-arguments -fobjc-legacy-dispatch -fobjc-abi-version=2 -mios-simulator-version-min=9.3 -lz -liconv -o /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/bin/iPhoneSimulator/Debug/SampleUsing.app/SampleUsing -dead_strip -u _xamarin_timezone_get_data -u _xamarin_log -u _UIApplicationMain -u _xamarin_get_block_descriptor -u '_OBJC_CLASS_$_ATInternet' -u '_OBJC_CLASS_$_Tracker' -u _mono_pmip -u _xamarin_dyn_objc_msgSend -u _xamarin_dyn_objc_msgSendSuper -u _xamarin_dyn_objc_msgSend_stret -u _xamarin_dyn_objc_msgSendSuper_stret
2>  Undefined symbols for architecture x86_64:
2>    "_OBJC_CLASS_$_Tracker", referenced from:
2>       -u command line option
2>    "_OBJC_CLASS_$_ATInternet", referenced from:
2>       -u command line option
2>  ld: symbol(s) not found for architecture x86_64
2>  clang: error: linker command failed with exit code 1 (use -v to see invocation)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): error : Native linking failed, undefined Objective-C class: Tracker. The symbol '_OBJC_CLASS_$_Tracker' could not be found in any of the libraries or frameworks linked with your application.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): error : Native linking failed, undefined Objective-C class: ATInternet. The symbol '_OBJC_CLASS_$_ATInternet' could not be found in any of the libraries or frameworks linked with your application.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): error : Native linking failed. Please review the build log.

我在这里把我的项目推到了github上

知道如何摆脱这个错误吗?

4

0 回答 0