libimobiledevice-win32 / imobiledevice-net

.NET (C#, VB.NET,...) bindings for libimobiledevice
GNU Lesser General Public License v2.1
299 stars 77 forks source link

UnknownError on idevice_connect #141

Open WimVriend opened 4 years ago

WimVriend commented 4 years ago

Hello experts,

I am looking for a way to receive realtime-data from an iPhone via USB and after reading this blog on the subject, I started a small VB .NET project (using VS2013). Getting imobiledevice.net with the packagemanager went fine and soon I was off to a promising start: I was able to get the name(s) from connected devices and I was even able to create an eventhandler to handle plugging and unplugging an iPhone. Great!

So today I thought: let's get some data! Unfortunately, that did not go so well. I do get a valid iDeviceHandle, but the idevice_connect function keeps returning '-2' (UnknownError). Logically that also leads to an invalid iDeviceConnectionHandle.

        Dim idevice As IiDeviceApi
        Dim deviceHandle As iDeviceHandle
        Dim connHandle As iDeviceConnectionHandle
        Dim ret As iMobileDevice.iDevice.iDeviceError

        idevice = LibiMobileDevice.Instance.iDevice
        ret = idevice.idevice_new(deviceHandle, udid)
        If (deviceHandle.IsInvalid) Then MsgBox("Invalid device handle: " + ret.ToString)

        ret = idevice.idevice_connect(deviceHandle, 5050, connHandle)
        If (ret <> iDeviceError.Success) Then MsgBox("Error: " + ret.ToString)
        If (connHandle.IsInvalid) Then MsgBox("Invalid connection handle: " + ret.ToString)

Does anyone have any clues for me, on how to fix this?

WimVriend commented 4 years ago

To add some info to my issue: I have installed the latest iTunes and have tried my little .NET program on W10 and W7. On the iOS side I have used peertalk-simple, which works fine between iPhone and Mac. I'd love to see it work with my PC...

WimVriend commented 4 years ago

I must say: response on this 'forum' is very meagre. Is there an imobiledevice-net developer or moderator out there?

NehaBector commented 4 years ago

Hi,

You can make connection and get data using ilibmobile binaries. I am able to take the backup of the iPhone device using these commands. I run commands in my process. Its supper easy.

Below are the commands which I am using for device pairing, fetching device info and taking backup:

For pairing: dir_name + "\binaries\idevicepair.exe pair"

For device space info: dir_name + "\binaries\ideviceinfo.exe -q com.apple.disk_usage"

For backup: dir_name + "\binaries\idevicebackup2.exe backup --full C:\Temp"

For help: dir_name + "\binaries\idevicebackup2.exe backup -h"

Hope this would resolve your problem.

WimVriend commented 4 years ago

Hello NehaBector,

I'm not sure how to fit your answer into my code. Do you mean I have to somehow 'pair' my host and the iPhone in some way? Where does your code go in my VB .NET example?

NehaBector commented 4 years ago

Hi WimVriend,

Instead of using nuget package you can run these binaries in vb.net process. I started using nuget packages but ended up getting no result. But binaries have everything. Yes you can pair the host with device though it works without that too but its better to pair to make sure the iPhone is connected with the host.

WimVriend commented 4 years ago

Hi again,

Is it possible to accomplish port forwarding with these binaries? I would like to establish a TCP connection between the iPhone and my .NET program.

WimVriend commented 4 years ago

Hi there!

After a short pause, I decided take a look at imobiledevice again, to see why it didn't work before. It took a bit of reading through other people's issues, when a lightbulb appeared above my head: you must start a 'socket listener' on the iPhone, before connecting!

The only thing that puzzles me is: why return an UnknownError? IMO a more explanatory errorcode (like NO_LISTENER_ON_PORT) would have helped me a lot...