1

是否可以通过底座连接器将 iMac 连接到 iPhone?我也在使用 EAAccessory 框架,但是当我将串行电缆连接到 iPhone 时,我没有收到任何通知。如果有人知道这件事,请给我一个建议。

4

4 回答 4

3

关于 EAAccessoryManager 和随附的类似乎有很多混淆。这些仅适用于 MFI 认可的硬件,即那些花时间遵循 MFI 计划并将必要的硬件集成到其设备中的制造商。

使用芯片和建立协议可以促进应用程序和设备之间的通信流。

Sam 在他的陈述中是正确的,但没有必要越狱您的应用程序以绕过 MFI 程序但是,如果您按照我将简要介绍的程序进行操作,您将无法提交到 App Store:

  1. 获取 IOKit iOS 开源浏览器的所有头文件
  2. 将它们添加到您的解决方案中
  3. 包含 IOKit.h 框架
  4. 前往http://www.arduino.cc/playground/Interfacing/Cocoa#IOKit了解如何使用 IOKit 和 icotl 命令来实现您所需的示例

我已经在 iOS 设备上成功实现了 IOKit 操作,所以只要您愿意放弃提交到 App Store,这绝对是可能的。

于 2011-10-31T22:06:34.970 回答
2

拉杰..

要获得连接附件的通知,您首先必须将您的附件注册到 MFI。否则你必须越狱你的 iPhone。越狱检查此代码

#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */

static struct termios gOriginalTTYAttrs;

static int OpenSerialPort()
{
    int        fileDescriptor = -1;
    int        handshake;
    struct termios  options;

    // Open the serial port read/write, with no controlling terminal, and don't wait for a connection.
    // The O_NONBLOCK flag also causes subsequent I/O on the device to be non-blocking.
    // See open(2) ("man 2 open") for details.

    fileDescriptor = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fileDescriptor == -1)
    {
        printf("Error opening serial port %s - %s(%d).\n",
               "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // Note that open() follows POSIX semantics: multiple open() calls to the same file will succeed
    // unless the TIOCEXCL ioctl is issued. This will prevent additional opens except by root-owned
    // processes.
    // See tty(4) ("man 4 tty") and ioctl(2) ("man 2 ioctl") for details.

    if (ioctl(fileDescriptor, TIOCEXCL) == -1)
    {
        printf("Error setting TIOCEXCL on %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // Now that the device is open, clear the O_NONBLOCK flag so subsequent I/O will block.
    // See fcntl(2) ("man 2 fcntl") for details.

    if (fcntl(fileDescriptor, F_SETFL, 0) == -1)
    {
        printf("Error clearing O_NONBLOCK %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // Get the current options and save them so we can restore the default settings later.
    if (tcgetattr(fileDescriptor, &gOriginalTTYAttrs) == -1)
    {
        printf("Error getting tty attributes %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }

    // The serial port attributes such as timeouts and baud rate are set by modifying the termios
    // structure and then calling tcsetattr() to cause the changes to take effect. Note that the
    // changes will not become effective without the tcsetattr() call.
    // See tcsetattr(4) ("man 4 tcsetattr") for details.

    options = gOriginalTTYAttrs;

    // Print the current input and output baud rates.
    // See tcsetattr(4) ("man 4 tcsetattr") for details.

    printf("Current input baud rate is %d\n", (int) cfgetispeed(&options));
    printf("Current output baud rate is %d\n", (int) cfgetospeed(&options));

    // Set raw input (non-canonical) mode, with reads blocking until either a single character 
    // has been received or a one second timeout expires.
    // See tcsetattr(4) ("man 4 tcsetattr") and termios(4) ("man 4 termios") for details.

    cfmakeraw(&options);
    options.c_cc[VMIN] = 1;
    options.c_cc[VTIME] = 10;

    // The baud rate, word length, and handshake options can be set as follows:

    cfsetspeed(&options, B19200);    // Set 19200 baud    
    options.c_cflag |= (CS8);  // RTS flow control of input


    printf("Input baud rate changed to %d\n", (int) cfgetispeed(&options));
    printf("Output baud rate changed to %d\n", (int) cfgetospeed(&options));

    // Cause the new options to take effect immediately.
    if (tcsetattr(fileDescriptor, TCSANOW, &options) == -1)
    {
        printf("Error setting tty attributes %s - %s(%d).\n",
            "/dev/tty.iap", strerror(errno), errno);
        goto error;
    }    
    // Success
    return fileDescriptor;

    // Failure "/dev/tty.iap"
error:
    if (fileDescriptor != -1)
    {
        close(fileDescriptor);
    }

    return -1;
}

int main(int args, char *argv[])
{
    int fd;
    char somechar[8];
    fd=OpenSerialPort(); // Open tty.iap with no hardware control, 8 bit, BLOCKING and at 19200 baud
    if(fd>-1)
    {
        write(fd,"*",1); // Write handshaking message over serial
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        // After this, our device or our PC program should be strobing serial ground to gain access to the Iphone Serial Line
        //////////////////////////////////////////////////////////////////////////////////////////////////
        read(fd,&somechar[0],1); // Read 1 byte  over serial.  This will block (wait) untill the byte has been received
        if(somechar[0]=='*') // Check if this byte is a "handshaking" message
        {
            printf("Serial connection established!\n"); // If it is, we have established a connection to the device and can freely read/write over serial!
            while(1) // Do this forever or untill someone presses CTRL+C
            {
                read(fd,&somechar[0],1);  // Read a character over serial!
                putchar(somechar[0]); // Write the character to the Terminal!!
            }
        }
    }
    return 0;
}
于 2011-10-31T04:15:23.823 回答
0

如果您将 iPhone 连接到 iMac 并且运行 iTunes 或 Xcode,您将能够看到 iPhone 已连接。

在 Xcode 中,转到 Organizer 窗口。在 iTunes 中,查看左侧栏中的“设备”下方。

我没用过的EAAccessory框架应该和这个无关。

于 2011-09-29T07:32:53.367 回答
0

答案是:连接外部附件时启动特定应用程序 - 并非所有附件都可以在连接时发出启动应用程序的信号。我认为普通的USB线也不能。

关于 IOKit:您可以从 Xcode 本身添加必要的文件 - 打开 Xcode.app 包。IOKit 框架位于 Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks 只需将缺少的文件(或制作链接)复制到

Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/IOKit.framework

内容/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/System/Library/Frameworks/IOKit.framework

也适用于所有模拟器平台

您应该知道,由于 iOS 沙盒安全性,并非 IOKit 的所有功能都可以在真实设备上运行(但它们可以在模拟器下运行)。但是您可以很好地使用 IORegistry。我在 iOS 上的第一个项目是 IORegistryExplorer 的实现。祝你好运!

于 2013-12-12T02:01:29.730 回答