1、將下載下來的sdk中的inc文件夾、mapapi.bundle、libbaidumapapi.a添加到工程中,其中libbaiduapi.a有兩個,一個對應模擬器一個對應真機,導入方法如下:
第一種方式:直接將對應平台的.a文件拖拽至XCode工程左側的Groups&Files中,缺點是每次在真機和模擬器編譯時都需要重新添加.a文件;
第二種方式:使用lipo命令將設備和模擬器的.a合並成一個通用的.a文件,將合並後的通用.a文件拖拽至工程中即可,具體命令如下:
lipo –create Release-iphoneos/libbaidumapapi.a Release-iphonesimulator/libbaidumapapi.a –output libbaidumapapi.a
第三種方式:
1.將API的libs文件夾拷貝到您的Application工程跟目錄下
2.在XCode的Project -> Edit Active Target -> Build -> Linking -> Other Linker Flags中添加-ObjC
3.設置靜態庫的鏈接路徑,在XCode的Project -> Edit Active Target -> Build -> Search Path -> Library Search Paths中添加您的靜態庫目錄,比 如"$(SRCROOT)/../libs/Release$(EFFECTIVE_PLATFORM_NAME)",$(SRCROOT)宏代表您的工程文件目錄,$(EFFECTIVE_PLATFORM_NAME)宏代表當前配置是OS還是simulator
我是用第二種方法,在真機和模擬器下都可以調試。
2、因為靜態庫采用Object C++實現,所以在工程中至少要有一個.mm的文件存在(可以把appdelegate.m改為.mm)
3、導入工程所需的框架:CoreLocation.framework,QuartzCore.framework,OpenGLES.framework,SystemConfiguration.framework
4、在AppDelegate中添加BMKMapManager對象,這裡要在百度地圖api網站上申請一個應用key
AppDelegate.h文件如下:
[cpp]
#import <UIKit/UIKit.h>
#import "TestViewController.h"
#import "BMapKit.h"
#define BaiduMapKey @"A56A733C30B159166B74AD41530CB013685035F9"
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
BMKMapManager* _mapManager;
}
@property (strong, nonatomic) UIWindow *window;
@end
#import <UIKit/UIKit.h>
#import "TestViewController.h"
#import "BMapKit.h"
#define BaiduMapKey @"A56A733C30B159166B74AD41530CB013685035F9"
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
BMKMapManager* _mapManager;
}
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m文件如下:
[cpp]
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_mapManager = [[BMKMapManageralloc] init];
BOOL ret = [_mapManagerstart:BaiduMapKey generalDelegate:nil];
if (!ret) {
NSLog(@"BMKMapManager start failed!");
}
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
TestViewController *root = [[TestViewControlleralloc] init];
self.window.rootViewController = root;
[self.windowmakeKeyAndVisible];
returnYES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_mapManager = [[BMKMapManageralloc] init];
BOOL ret = [_mapManagerstart:BaiduMapKey generalDelegate:nil];
if (!ret) {
NSLog(@"BMKMapManager start failed!");
}
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
TestViewController *root = [[TestViewControlleralloc] init];
self.window.rootViewController = root;
[self.windowmakeKeyAndVisible];
returnYES;
}