- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
你好,我正在尝试将 google admboads 更新到 V6,但我在绑定(bind)以下内容并将其暴露给托管世界时遇到了一些麻烦
我有以下结构
typedef struct GADAdSize {
CGSize size;
NSUInteger flags;
} GADAdSize;
我在单点触控方面做了这个
[StructLayout(LayoutKind.Sequential)]
public struct GADAdSize
{
public SizeF size;
public uint flags;
}
我有以下代码
extern GADAdSize const kGADAdSizeBanner;
extern GADAdSize const kGADAdSizeMediumRectangle;
我无法使用 [Field] 属性绑定(bind)它,因为文档指定 Field 属性只能用于
所以我尝试了以下2种我能想到的方法
[DllImport ("__Internal")]
extern static IntPtr kGADAdSizeMediumRectangle ();
public static GADAdSize MediumRectangle
{
get
{
object obj = Marshal.PtrToStructure(kGADAdSizeMediumRectangle(), typeof(GADAdSize));
return (GADAdSize) obj;
}
}
和
public static GADAdSize Banner
{
get
{
var handle = Dlfcn.dlopen ("libGoogleAdMobAds", 0);
IntPtr ptr = Dlfcn.GetIntPtr(handle, "kGADAdSizeBanner");
Dlfcn.dlclose (handle);
object obj = Marshal.PtrToStructure(ptr, typeof(GADAdSize));
return (GADAdSize) obj;
}
}
并且在这两个方面它都崩溃了
使用 DLLImport 我在调用 Marshal.PtrToStructure() 时得到一个 nullargument 异常,第二个异常引发
DLLNotFoundException
System.ArgumentNullException
在此先感谢您的帮助
亚历克斯
编辑:
对不起@Poupou 我的错,它抛出 System.ArgumentNullException 句柄值为 0,ptr 值为 0
堆栈跟踪是:
System.ArgumentNullException: Argument cannot be null.
Parameter name: src
at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal:PtrToStructure (intptr,System.Type)
at AlexTouch.GoogleAdMobAds.GADAdSizeConstants.get_Banner () [0x00000] in <filename unknown>:0
at MobclixText.MobclixTextViewController.ViewDidLoad () [0x00006] in /Users/Alex/Projects/MobclixText/MobclixText/MobclixTextViewController.cs:33
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:98
at MobclixText.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00031] in /Users/Alex/Projects/MobclixText/MobclixText/AppDelegate.cs:44
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at MobclixText.Application.Main (System.String[] args) [0x00000] in /Users/Alex/Projects/MobclixText/MobclixText/Main.cs:17
我猜这是因为句柄为 0。
关于您的评论
Using dlsym with one of the special flags (man dlsym) might help.
你能给我一个如何使用它的例子吗=) ??
亚历克斯
编辑 2:
你好@Poupou,感谢你的回答,但是
IntPtr RTLD_MAIN_ONLY = (IntPtr) (-5);
IntPtr ptr = Dlfcn.GetIntPtr (RTLD_MAIN_ONLY, "kGADAdSizeBanner");
我仍然得到 ptr
等于 0
还有其他想法吗?
亚历克斯
编辑 3:
好的,我现在正在尝试以下操作
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "kGADAdSizeBanner");
Console.WriteLine("RTLD_MAIN_ONLY: " + RTLD_MAIN_ONLY);
Console.WriteLine("ptr: " + ptr);
Dlfcn.dlopen (null, 0);
完成 here现在我得到一个句柄值 -2
但我猜 native 链接器现在正在删除该符号,我怎样才能防止这种情况发生?
非常感谢你的时间@Poupou
亚历克斯
最佳答案
所以我找到了一种获取值的方法。第一部分是说服链接器导出符号(不隐藏任何现有符号)。这可以通过创建(本地)符号的别名(默认情况下是全局的)来完成。例如
-gcc_flags="-Xlinker -alias -Xlinker _kGADAdSizeBanner -Xlinker _MTAdSizeBanner"
之后的代码:
IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0);
IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "MTAdSizeBanner");
object obj2 = Marshal.PtrToStructure(ptr, typeof(GADAdSize));
将为您提供一个值为 320x50 的 GADAdSize
实例。
你需要重新导出你需要的每个符号(糟糕)但是应该可以将它包含在 [LinkWith]
属性中(iirc)所以它不是必需的对于最终用户。
关于c# - MonoTouch 绑定(bind)不能使用字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10525043/
在下图中,您可以看到在列表的 StyleStringElement 中,当快速滚动时标题呈现黑色。如果我旋转 ipad,列表会重新呈现并且没问题。 有变通办法吗? 最佳答案 不确定是什么问题,但之前已
如何将 UISegmentedControl 放入 MonoTouch.Dialog header 部分? 最佳答案 是的,您可以像操作任何常规 UIView 一样操作 Section 类的 Head
我正在使用 MonoTouch 构建一个 iPhone 应用程序,它从网络服务获取数据。 我遇到的麻烦是第一个屏幕显示了国家列表。当用户选择一个国家时,它应该只从网络服务中检索该选定国家的城市列表..
我正在使用 MonoTouch 开发一款仅限 iPad 的调查应用程序。使用 monotouch.dialog (mt.d),我发现构建这些界面可以很快,这太棒了。 但是...我还发现 mt.d 只能
我有一个标准 View ,顶部有一个导航栏。我还在它自己的源文件中设置了一个 Monotouch.Dialog。我四处寻找解决方案,但似乎找不到关于如何将 MTD 添加到普通 View 的明确答案。
我需要来自 monotouch-bindings 的 facebook api 包装器,所以我从 github 下载了 monotouch-bindings 的整个包. 我无法编译 facebook
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this q
到目前为止,我发现的所有关于在 iPad/iPhone 应用程序中使用 Sqlite 数据库的代码示例都使用脚本在应用程序部署后创建数据库。 但是是否可以在 monotouch 中创建数据库、构建结构
我的应用程序在 MT 3.0 中运行良好。现在,当我升级时。当按钮位于 ContentView 中时,我看到错误。单击按钮时会发生崩溃。代码: public override UITableViewC
我已经决定开始编写一个 iPhone 应用程序并且来自 c# 背景,我想我会开始使用单声道进行开发。 虽然这个问题可能是主观的,但我希望您能提供一些指导。 使用这项技术开发我的应用是否安全,或者我应该
每次我尝试部署我的项目时,都会收到以下错误: Compiling to native code /Developer/MonoTouch/usr/bin/mtouch -sdkroot "/Appli
下面的代码给出了警告: Warning CS0618: MonoTouch.Dialog.Section.Add(System.Collections.Generic.IEnumerable)' is
在我用 MonoDevelop (3.0.3.5) 创建的解决方案中,我有 3 个项目: 带 UI 的 MonoTouch 项目, 带有 iOS 特定代码的 MonoTouch 库项目, 具有域模型的
我已经用模拟器简单地试用了 MT,并决定在加入开发计划的同时购买它。程序似乎可以在模拟器上运行,但当部署到我的(运行 5.1 的最新型号)iPad 上时,程序会在运行时立即崩溃。这是在做任何事情之前!
我希望能够捕捉图像(或从照片库中选择图像)并使用 Monotouch 将其上传到远程服务器。我不确定如何获取和编码图像或如何上传图像,而且我很难找到相关说明。你能帮我开始吗?谢谢你。 最佳答案 您要找
我是一名 .NET 开发人员,试图跨入 Objective-C iPhone 编程。我创建了我的第一个应用程序 - 只是一个包含多个 xib 的简单组合。 我刚刚接触到 MonoTouch,它可以让您
当 iPhone 或 iPad 应用程序抛出错误时,建议使用 Monotouch 获取报告数据的方法是什么? 最佳答案 我只是使用 Console.WriteLine 和一个围绕它的小包装器,这可以帮
在 iPhone/iPod 上的 Monotouch 中,如何检测是否有可用的互联网连接? 最佳答案 现在最好的方法是使用 Miguel de Icaza 的 GitHub 存储库中的此类: http
众所周知,Apple does not provide automatic garbage collection on the iPhone to prolong battery life 。然而据报
MonoTouch 总是与 C# 一起提及。该框架和工具集实际上仅限于 C#,还是其他 CLR 语言(如 IronRuby 和 F#)也可以工作? 最佳答案 它不仅限于 C#,但运行其他语言有一些注意
我是一名优秀的程序员,十分优秀!