Xamarin.iOS中的问题绑定协议

时间:2014-08-29 19:23:14

标签: c# ios xamarin.ios xamarin

我正在尝试使用Xamarin.iOS绑定库绑定objective-c协议。我遇到的问题是生成界面在编译时对我的任何C#代码都不可见。我正在使用documentation section on Xamarin讨论“MonoTouch 7.0中的新功能”协议绑定过程。

这是我的目标-c协议:

@protocol SomeApplicationDelegate <NSObject>

- (void)displayAboutView;
- (void)displaySettingsView;
- (void)displayMessagesView;

- (void)presentSetup;

@end

我的ApiDefinition看起来像这样:

[Model, Protocol]
[BaseType (typeof (NSObject))]
interface SomeApplicationDelegate {
    [Export("displayAboutView")]
    void DisplayAboutView();

    [Export("displaySettingsView")]
    void DisplaySettingsView();

    [Export("displayMessagesView")]
    void DisplayMessageView();

    [Export("presentSetup")]
    void PresentSetup();
}

interface ISomeApplicationDelegate {}

[BaseType(typeof(NSObject))]
interface SomeApplicationDelegateTool {
    [Export ("getProtocol")]
    ISomeApplicationDelegate GetProtocol ();
}

最后,我正在尝试在AppDelegate上实现生成的接口/协议:

[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate, ISomeApplicationDelegate
{
    // class-level declarations

    public override UIWindow Window {
        get;
        set;
    }

    public UITabBarController TabBarcontroller {
        get;
        private set;
    }

    public override void OnResignActivation (UIApplication application)
    {
    }

    public override void DidEnterBackground (UIApplication application)
    {
    }

    public override void WillEnterForeground (UIApplication application)
    {
    }

    public override void WillTerminate (UIApplication application)
    {
    }

    public void DisplayAboutView() {        
    }

    public void DisplaySettingsView(){
    }

    public void DisplayMessageView(){
    }

    public void PresentSetup(){
    }
}

这是构建日志的输出:

Compiling to native code
/Developer/MonoTouch/usr/bin/mtouch -sdkroot "/Applications/Xcode6-Beta6.app/Contents/Developer" --cache "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache" --nomanifest --nosign -dev "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/bin/iPhone/Debug/SomeiPhone.app" -r "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iOS.Raw/bin/Debug/Some.iOS.Raw.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -debug -linksdkonly -sdk "8.0" -targetver "7.0" --abi=armv7,armv7s "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/bin/iPhone/Debug/SomeiPhone.exe"
Xamarin.iOS 7.9.3 Trial Edition using framework: /Applications/Xcode6-Beta6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk
Process exited with code 1, command:
/Applications/Xcode6-Beta6.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -lxml2 -lz -Wl,-pie  -arch armv7 -arch armv7s -miphoneos-version-min=7.0 -isysroot /Applications/Xcode6-Beta6.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.0.sdk "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/SomeiPhone.exe.armv7.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/SomeiPhone.exe.armv7s.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7s.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7s.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/System.dll.armv7.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/System.dll.armv7s.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/Some.iOS.Raw.dll.armv7.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/Some.iOS.Raw.dll.armv7s.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/registrar.armv7.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/registrar.armv7s.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/main.armv7.o" "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/main.armv7s.o" -force_load "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/libSome.a" -o "/Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/bin/iPhone/Debug/SomeiPhone.app/SomeiPhone" -framework Foundation -framework CoreGraphics -framework UIKit -framework CFNetwork -framework MobileCoreServices -framework MessageUI -framework CoreLocation -framework MapKit -framework QuartzCore -framework SystemConfiguration -framework AddressBook -framework AddressBookUI -lz -liconv -u _mono_pmip -u _monotouch_log -u _monotouch_release_managed_ref -u _monotouch_create_managed_ref -u _xamarin_get_block_descriptor /Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonoboehm-2.0.a /Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonotouch-debug.a
ld: warning: ignoring file /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/SomeiPhone.exe.armv7s.o, file was built for armv7s which is not the architecture being linked (armv7): /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/SomeiPhone.exe.armv7s.o
ld: warning: ignoring file /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7s.o, file was built for armv7s which is not the architecture being linked (armv7): /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7s.o
ld: warning: ignoring file /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7s.o, file was built for armv7s which is not the architecture being linked (armv7): /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7s.o
ld: warning: ignoring file /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/System.dll.armv7s.o, file was built for armv7s which is not the architecture being linked (armv7): /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/System.dll.armv7s.o
ld: warning: ignoring file /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/Some.iOS.Raw.dll.armv7s.o, file was built for armv7s which is not the architecture being linked (armv7): /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/Some.iOS.Raw.dll.armv7s.o
ld: warning: ignoring file /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/registrar.armv7s.o, file was built for armv7s which is not the architecture being linked (armv7): /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/registrar.armv7s.o
ld: warning: ignoring file /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/main.armv7s.o, file was built for armv7s which is not the architecture being linked (armv7): /Users/dfrisk/Dev/temp/Some Prototype/Some.Mobile/Some.iPhone/obj/iPhone/Debug/mtouch-cache/main.armv7s.o
Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_SomeApplicationDelegateTool", referenced from:
      objc-class-ref in registrar.armv7.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error MT5211: Native linking failed, undefined Objective-C class: _OBJC_CLASS_$_SomeApplicationDelegateTool. If '_OBJC_CLASS_$_SomeApplicationDelegateTool' is a protocol from a third-party binding, please check that it has the [Protocol] attribute in its api definition file, otherwise verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
error MT5202: Native linking failed. Please review the build log.

我是创建绑定的新手,所以我不确定如何弄清楚到底出了什么问题。据我所知,看起来我已经正确地遵循了这些步骤。而且我似乎拥有xcode项目中所有相同的框架引用。

我的linkWith.cs有这个:

[assembly: LinkWith ("libSome.a", LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, ForceLoad = true, Frameworks = "MobileCoreServices CFNetwork MessageUI CoreGraphics CoreLocation MapKit QuartzCore SystemConfiguration UIKit Foundation AddressBook AddressBookUI", LinkerFlags = "-lxml2 -lz")]

我在连接libxml2和libz库时遇到了问题,但我认为现在没问题。

根据我对该过程的理解以及文档所说的内容,我的界面似乎应该可用。 Intellisense显示库名称空间下可用的ISomeApplicationDelegate,但在编译时我得到构建错误。我不知道从哪里开始。有什么想法吗?

0 个答案:

没有答案