ドックコネクタを介して iMac を iPhone に接続できますか? また、EAAccessory フレームワークを使用していますが、シリアル ケーブルを iPhone に接続しても通知が届きません。誰かがこれについて知っているなら、私に提案をしてください。
4 に答える
EAAccessoryManager と付随するクラスに関しては、多くの混乱があるようです。これらは、MFI 認可のハードウェア、つまり、時間をかけて MFI プログラムに従い、必要なハードウェアをデバイスに統合したメーカーでのみ使用できます。
チップの使用とプロトコルの確立により、アプリとデバイス間の通信ストリームが容易になります。
Sam の発言は正しいですが、MFI プログラムを回避するためにアプリをジェイルブレイクする必要はありませんが、これから簡単に説明する手順に従えば、App Store に提出することはできません。
- IOKit iOS OpenSource Browserのすべてのヘッダー ファイルを取得します。
- それらをソリューションに追加します
- IOKit.h フレームワークを含める
- IOKitおよび icotl コマンドを使用して必要なものを実現する方法の例については、http: //www.arduino.cc/playground/Interfacing/Cocoa#IOKit にアクセスしてください。
私は iOS デバイスに IOKit 操作を正常に実装したので、App Store への提出を差し控える意思がある限り、これは間違いなく可能です。
ラージ..
接続アクセサリの通知を受け取るには、まずアクセサリを 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;
}
iPhone を iMac に接続し、iTunes または Xcode を実行している場合、iPhone が接続されていることを確認できます。
Xcode で、[オーガナイザー] ウィンドウに移動します。iTunes で、左側の列の [デバイス] の下を見てください。
私が使用していない EAAccessory フレームワークは、これとは何の関係もないはずです。
答えは次のとおりです。外部アクセサリが接続されているときに特定のアプリを起動 します - すべてのアクセサリが接続されているときにアプリを起動するように通知できるわけではありません。普通のUSBケーブルでもダメだと思います。
IOKit について: Xcode 自体から必要なファイルを追加できます - Xcode.app パッケージを開きます。IOKit フレームワークは Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks にあります。存在しないファイルをコピーする (またはリンクを作成する) だけです。
内容/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 の実装でした。幸運を!