2017-04-07 51 views
1

我試圖調用Objective-C的方法如何公開Objective-C的指針移動方法,WithResultBuffer在IOS綁定

-(nabto_status_t)nabtoRpcInvoke:(NSString *)url withResultBuffer:(char 
    **)jsonResponse; 

我使用的Objective-記號筆工具來生成跟蹤方法

[Export("nabtoRpcInvoke:withResultBuffer:")] 
unsafe nabto_status_t RpcInvoke(string url, ref byte jsonResponse); 

請幫助正確公開我,這樣我就可以得到我可以在IOS應用程序中使用的JsonResponse字符串。

+0

您正在使用iOS Frameworks或Xamarin.iOS庫綁定? – XTL

+0

我正在使用Xamarin.IOS庫綁定。 –

+0

只是清除目標sharpie生成 [導出(「nabtoRpcInvoke:withResultBuffer:」)] 不安全nabto_status_t RpcInvoke(字符串url,sbyte jsonResponse);我添加了ref從指針得到輸出。作爲它的char ** –

回答

0

我做了這些更改生成的方法

[Export("nabtoRpcInvoke:withResultBuffer:")] 
     unsafe nabto_status_t RpcInvoke(string url, ref IntPtr 
     jsonResponse); 

,然後我得到了JsonResonse如下。

 IntPtr buff=new IntPtr() ; 
     status = Client.RpcInvoke(URL, ref buff); 

     byte[] newArray = new byte[buff.ToInt32() + 1]; 

     for (int m = 0; m < buff.ToInt32(); m++) 
     { 
      byte b = Marshal.ReadByte(buff,m); 
      newArray[m] = b; 
     } 


     var JsonResponse = System.Text.Encoding.UTF8.GetString(newArray); 
相關問題