首页 > 解决方案 > 了解使用 libimobiledevice 进行 Android 到 iOS 连接时的连接问题

问题描述

我正在尝试构建一个原型 Android 应用程序,用于将我的 Android 设备无线连接到 iOS 设备。在研究选项时,我遇到了似乎很合适的libimobiledevice 库。我目前陷入了似乎iOS设备正在接收请求但拒绝它的问题,这就是我想从这个论坛了解的内容。

到目前为止我做了什么:

lockdownd[70] <Notice>: _receive_message: <private>
symptomsd(SymptomEvaluator)[120] <Notice>: Data Usage for lockdownd - WiFi in/out: 181637370/198768065, WiFi delta_in/delta_out: 458/0, Cell in/out: 0/0, Cell delta_in/delta_out: 0/0, RNF: 0, subscriber tag: 0

问题:

谢谢!

标签: androidioslibimobiledevice

解决方案


libimobiledevice 依赖于 usbmux,而对于 Linux,这目前无法无线工作。您可以通过使用 usbmuxd2 重新实现来克服这个问题。

这是我的脚本,用于在树莓派上启动并运行完整的 linux 实现。我在这里也有一个更加用户友好的浏览器:nMirrior

#!/bin/bash

echo "installing dependencies"

read -p "Do you want to update/install build tools (you need to if this is a new image) (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
    sudo apt-get -q update
    sudo apt-get -q install \
                    build-essential \
                    checkinstall \
                    git \
                    autoconf \
                    automake \
                    libtool-bin
fi


echo "installing libatomic"
sudo apt-get -q install libatomic-ops-dev libatomic1


echo "installing libimobiledevice dependencies"
sudo apt-get -q install \
                libplist-dev \
                libusbmuxd-dev \
                libimobiledevice-dev \
                libusb-1.0-0-dev \
                libplist++-dev \
                libssl-dev \
                usbmuxd \
                udev \
                libavahi-client-dev \
                avahi-utils 



echo "Starting nMirror setup"

# Configure source directories
nMirrorDir=~/nMirror

echo "The applications needed for nMirror will be installed in $nMirror"

libplistDir=$nMirrorDir/libplist
libusbmuxdDir=$nMirrorDir/libusbmuxd
libimobiledeviceDir=$nMirrorDir/libimobiledevice
libgeneralDir=$nMirrorDir/libgeneral
usbmuxd2Dir=$nMirrorDir/usbmuxd2

#Standard libimobiledevice repos
libplistGit=https://github.com/libimobiledevice/libplist.git
libusbmuxdGit=https://github.com/libimobiledevice/libusbmuxd.git
libimobiledeviceGit=https://github.com/libimobiledevice/libimobiledevice.git

#tihmstar repo for usbmuxd2 to support network connection to iDevice
usbmuxd2Git=https://github.com/tihmstar/usbmuxd2.git
libgeneralGit=https://github.com/tihmstar/libgeneral.git



# Create the project directory if it does not exist
mkdir -p $nMirrorDir
cd $nMirrorDir


# Fetch the repos

fetchnext=false
if test -d $libplistDir; then
    read -p "libplist directory exists. Remove and re-fetch new? (y/n): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        rm -rf $libplistDir
        fetchnext=true
    fi
else
    fetchnext=true
fi
if [ "$fetchnext" == true ]; then
    echo "Cloning from git.  1 - libplist"
    cd $nMirrorDir
    git clone --quiet $libplistGit
    cd $libplistDir
    # git checkout 2.2.0 # Cannot go back to the last tag (2.2.0) because usbmuxd2 want 2.2.1 - just get the head for now
fi


if test -d $libusbmuxdDir; then
    read -p "libusbmuxd directory exists. Remove and re-fetch new? (y/n): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        rm -rf $libusbmuxdDir
        fetchnext=true
    fi
else
    fetchnext=true
fi
if [ "$fetchnext" == true ]; then
    echo "Cloning from git.  2 - libusbmuxd (Normal)"
    cd $nMirrorDir
    git clone --quiet $libusbmuxdGit
    cd $libusbmuxdDir
    git checkout 2.0.2
fi

if test -d $libimobiledeviceDir; then
    read -p "libimobiledevice directory exists. Remove and re-fetch new? (y/n): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        rm -rf $libimobiledeviceDir
        fetchnext=true
    fi
else
    fetchnext=true
fi
if [ "$fetchnext" == true ]; then
    echo "Cloning from git.  3 - libimobiledevice"
    cd $nMirrorDir
    git clone --quiet $libimobiledeviceGit
    cd $libimobiledeviceDir
    git checkout 1.3.0
fi


#tihmstar repo for usbmuxd2 to support network connection to iDevice
if test -d $libgeneralDir; then
    read -p "libgeneral directory exists. Remove and re-fetch new? (y/n): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        rm -rf $libgeneralDir
        fetchnext=true
    fi
else
    fetchnext=true
fi
if [ "$fetchnext" == true ]; then
    echo "Cloning from git.  4 - libgeneral (tihmstar Experimental repo tag 55)"
    cd $nMirrorDir
    git clone --quiet $libgeneralGit
    cd $libgeneralDir
    git checkout 55
fi


if test -d $usbmuxd2Dir; then
    read -p "usbmuxd2 directory exists. Remove and re-fetch new? (y/n): " -n 1 -r
    echo
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
        rm -rf $usbmuxd2Dir
        fetchnext=true
    fi
else
    fetchnext=true
fi
if [ "$fetchnext" == true ]; then
    echo "Cloning from git.  5 - usbmuxd2 (tihmstar Eperimental repo)"
    cd $nMirrorDir
    git clone --quiet $usbmuxd2Git
    cd $usbmuxd2Dir
    git submodule init
    git submodule update
fi

#build stage

cd $libplistDir
./autogen.sh
make
sudo make install

cd $libusbmuxdDir
./autogen.sh
make
sudo make install

cd $libimobiledeviceDir
./autogen.sh
make
sudo make install

sudo ldconfig

#configure Avahi for zeroconf as per https://www.raspberrypi.org/forums/viewtopic.php?t=267113
#Note: Zeroconf may not be desirable - use with caution
cd $nMirrorDir

#create avahi patch
tee avahi.patch <<EOF
--- /etc/avahi/avahi-daemon.conf 2021-08-16 23:59:16.917672251 +0100
+++ /etc/avahi/avahi-daemon_usbmuxd.conf 2021-08-17 09:45:02.096575347 +0100
@@ -20,7 +20,7 @@
 
 [server]
 #host-name=foo
-#domain-name=local
+domain-name=local
 #browse-domains=0pointer.de, zeroconf.org
 use-ipv4=yes
 use-ipv6=yes
@@ -46,8 +46,8 @@
 #disable-user-service-publishing=no
 #add-service-cookie=no
 #publish-addresses=yes
-publish-hinfo=no
-publish-workstation=no
+publish-hinfo=yes
+publish-workstation=yes
 #publish-domain=yes
 #publish-dns-servers=192.168.50.1, 192.168.50.2
 #publish-resolv-conf-dns-servers=yes
EOF

cd /etc
sudo patch -p2 < $nMirrorDir/avahi.patch

#enable the avahi-daemon
systemctl list-unit-files avahi-daemon.service
#activate/enable the avahi-daemon.service
sudo systemctl enable avahi-daemon.service
sudo systemctl start avahi-daemon.service
sudo systemctl restart avahi-daemon.service
#enable ssh service
sudo systemctl enable ssh.service
sudo systemctl start ssh.service
#avahi-browse -a 


# if using gcc: the patch below works to include -latomic 
# if using clang: make CXX=clang++

cd $libgeneralDir
./autogen.sh
make CFLAGS="-g -O2 -std=c11 -latomic" LDFLAGS=-latomic
sudo make install

sudo ldconfig

cd $usbmuxd2Dir

#create log patch
#cassure only needed for versions after 55 - probably remove this as checkout is fixed to 55
tee log.patch <<EOF
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,7 @@ case $host_os in
         have_mdns="yes"
         ;;
   *)
-        LDFLAGS+=" -lstdc++fs"
+        LDFLAGS+="-latomic -lstdc++fs"
         ;;
 esac
 
EOF

git apply log.patch
./autogen.sh
make
sudo make install

sudo ldconfig


# get the BT PAN up and running
sudo apt-get install bluez-tools

sudo tee /etc/systemd/network/pan0.netdev <<EOF
[NetDev]
Name=pan0
Kind=bridge
EOF
 
 
sudo tee /etc/systemd/network/pan0.network <<EOF
[Match]
Name=pan0
[Network]
Address=172.20.1.1/24
DHCPServer=yes
EOF
 
sudo tee /etc/systemd/system/bt-agent.service <<EOF
[Unit]
Description=Bluetooth Auth Agent
 
[Service]
#ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
ExecStart=/bin/sh -c '/usr/bin/yes | /usr/bin/bt-agent --capability=NoInputNoOutput' #autoaccept
Type=simple
 
[Install]
WantedBy=multi-user.target
EOF
 
sudo tee /etc/systemd/system/bt-network.service <<EOF
[Unit]
Description=Bluetooth NEP PAN
After=pan0.network
[Service]
ExecStart=/usr/bin/bt-network -s nap pan0
Type=simple
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable systemd-networkd
sudo systemctl enable bt-agent
sudo systemctl enable bt-network
sudo systemctl start systemd-networkd
sudo systemctl start bt-agent
sudo systemctl start bt-network

sudo bt-adapter --set Discoverable 1

# list devices. Need to ask the user to connect via USB the first time using idevicesyslog. Then make the BT PAN connection and connect via idevicesyslog -n

/usr/local/bin/idevice_id 

推荐阅读