18

我已经看到了很多关于此的问题,但没有人真正给出真正的答案(要导入的框架、实际代码等)。他们只说使用私有 api,这会让您的应用被应用商店拒绝。

我知道使用私有 api 会使我的应用程序被拒绝,因为我想知道如何将其用于个人用途。(iPhone SDK 3.1.2, iPod touch 2g)

4

6 回答 6

10

我也一直在研究这个。您需要在项目中包含蓝牙管理器框架和头文件。它应该

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework/

如果头文件不存在,您需要获取从库生成的 .h 文件并将其包含在您的项目中。我用谷歌搜索找到它;这是一个:

http://iphone-dev.googlecode.com/svn/branches/include-1.2-sdk/include/BluetoothManager/

一旦将它添加到您的项目中,如果头文件已经在框架中,您的导入应该如下所示:

#import <BluetoothManager/BluetoothManager.h>

或者,如果您将自己的 BluetoothManager.h 文件添加到您的项目中:

#import "BluetoothManager.h

要在此处切换蓝牙是代码:

BluetoothManager *manager = [BluetoothManager sharedInstance];
[manager setEnabled:![manager enabled]];    

我自己构建了一个实用程序来执行此操作,并且确实有效。请注意,如果您只想创建一个实用程序来切换蓝牙并退出,而无需任何 UI,请在 XCode 中创建一个新项目并使用基于窗口的应用程序模板。将代码添加到 didFinishLaunchingWithOptions 方法并替换[window makeKeyAndVisible]exit(0).

于 2010-02-02T22:00:51.203 回答
7

您需要确保二进制文件和头文件都位于以下 PrivateFrameworks 文件夹中:

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/PrivateFrameworks

这将允许您将诸如 BluetoothManager.framework 之类的 PrivateFrameworks 导入您的应用程序而不会出错。您可以找到如何在线获取标题。这适用于 3.1.2 +,因为我现在正在编写一个可以在我的设备和 Sim 上完美运行的应用程序。

如果您要在模拟器中进行测试,请使用以下命令:

#if TARGET_IPHONE_SIMULATOR
        //This is where simulator code goes that use private frameworks
#else
        /* this works in iOS 4.2.1 */
        Class BluetoothManager = objc_getClass("BluetoothManager");
        id btCont = [BluetoothManager sharedInstance];
        [btCont setPowered:YES];
#endif
于 2009-12-12T02:38:37.107 回答
5
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

#if TARGET_IPHONE_SIMULATOR
    exit( EXIT_SUCCESS ) ;
#else
    /* this works in iOS 4.2.3 */
    Class BluetoothManager = objc_getClass( "BluetoothManager" ) ;
    id btCont = [BluetoothManager sharedInstance] ;
    [self performSelector:@selector(toggle:) withObject:btCont afterDelay:1.0f] ;
#endif
    return YES ;
}

#if TARGET_IPHONE_SIMULATOR
#else
- (void)toggle:(id)btCont
{
    BOOL currentState = [btCont enabled] ;
    [btCont setEnabled:!currentState] ;
    [btCont setPowered:!currentState] ;

}
#endif

上述方法适用于 iOS 4.2.3

于 2011-07-07T06:39:12.907 回答
3

要使 BluetoothManager 私有 api 工作,您需要执行以下操作: 1. 获取 Harkonian 指示的 4 个头文件并将它们添加到您的 SDK 文件(将头文件添加到您的项目) 2. 将框架添加到您的项目(添加二进制文件到您的项目) 3. 创建一个变量,用于使用 BluetoothManager 服务 示例:btManager = [BluetoothManager sharedInstance]; 4.使用BluetoothManager的方法,都可以在BluetoothManager.h中看到

我整理了一个完整的示例,可在此处获得:http ://www.pocketmagic.net/?p=2827

希望这会有所帮助,拉杜

于 2012-07-16T20:46:49.667 回答
0

I believe the solution is to make a system call to launchctl since that's the daemon responsible for starting/stopping system services.

于 2009-11-16T18:48:26.077 回答
0

使用 Iphone 5s
[btCont setEnabled:!currentState] ;[btCont setPowered:!currentState] ;
不运行

于 2014-09-03T04:21:48.163 回答