Link to the API development tutorial on Baidu map Official Website: Click to open the link
I followed his tutorial to make the error "Apple Mach-O linker command failed with exit code 1", so I had to search the Internet.
Let's talk about how to build the environment: the cause of my error is that the path error occurs when a static library is introduced.
1. Click the download link to open the link.
2. Decompress the package as follows:
3. copy and paste the preceding three inc libs mapapi. bundle files to the project root directory.
Click the project name in Xcode. Add projects to "XXX" in principle to add libbaidumapapi. a In the inc folder, mapapi. bundle file, and libs/Release-iphoneos folder to the project.
4. Almost all third-party map sdks depend on apple's own frameworks. Therefore, we need to import this step: CoreLocation. framework and QuartzCore. framework, OpenGLES. framework, SystemConfiguration. framework, CoreGraphics. framework. The import method is as follows:
5.
Introduce static library files
1) In XCode Project> Edit Active Target> Build> Linking> Other Linker Flags, add-ObjC
2 ). set the link Path of the static Library, add your static Library directory to XCode Project> Edit Active Target> Build> Search Path> Library Search Paths, $ (SRCROOT) /libs/Release $ (inclutive_platform_name)
This one in Library Search Paths is enough to delete other
Note: The static library is implemented using ObjectC ++. Therefore, you must ensure that at least one of your projects is available. mm suffix source file (you can set any one. the file with the m suffix is renamed. mm), or specify the compilation method in the project properties, set XCode Project-> Edit Active Target-> Build-> GCC4.2-Language-> Compile Sources As to "Objective-C ++"
6.
Select the project, target, switch to the Build Setting tag, and locate the other link flag,
Input:-all_load
7. The rest is only code work. Because key verification is required, we need to first use the BMKMapManager class to configure the applied key for authorization. Select AppDelegate. h
[Plain]View plaincopy
- # Import "BMapKit. h" // import BMapKit. h
-
- @ Interface AppDelegate: UIResponder {
- BMKMapManager * _ mapManager; // instantiate
- } Select AppDelegate. m, change. mm, (note: ObjectC ++ is used in the static library. Therefore, you must ensure that at least one of your projects exists. mm suffix source file (you can set any one. the file with the m suffix is renamed. mm ))
[NOTE: If there is no mm, a large number of errors will be reported during running]
Add the following code to didfinishlaunchingwitexceptions in AppDelegate. mm:
[Plain]View plaincopy
- -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
- {
- // To use Baidu map, start BaiduMapManager first
- _ MapManager = [[BMKMapManager alloc] init];
- // If you want to pay attention to network and authorization verification events, set the generalDelegate parameter.
- BOOL ret = [_ mapManager start: @ "Your applied ak" generalDelegate: nil];
- If (! Ret ){
- NSLog (@ "manager start failed! ");
- }
- Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
- // Override point for customization after application launch.
- Self. viewController = [[[ZYViewController alloc] initWithNibName: @ "ZYViewController" bundle: nil] autorelease];
- Self. window. rootViewController = self. viewController;
- [Self. window makeKeyAndVisible];
- Return YES;
- }
8. Add the following code to viewcontroller. m to display the map:
[Plain]View plaincopy
- # Import "ViewController. h"
- # Import "BMKMapView. h"
-
- @ Interface ViewController ()
-
- @ End
-
- @ Implementation ViewController
-
- -(Void) viewDidLoad
- {
- [Super viewDidLoad];
- BMKMapView * mapView = [[BMKMapView alloc] initWithFrame: CGRectMake (0, 0,320,460)];
- Self. view = mapView;
- }
After importing BMKMapView. h, instantiate the BMKMapView class.
From 2.0.0, The viewWillAppear and viewWillDisappear methods are added to BMKMapView to control the lifecycle of BMKMapView. In addition, only one BMKMapView can receive callback messages at a time, therefore, in viewController using BMKMapView, you need to call the corresponding method of BMKMapView in the viewWillAppear and viewWillDisappear methods and process the delegate. The Code is as follows:
Source code copy printing
- (Void) viewWillAppear :( BOOL) animated
- {
- [_ MapView viewWillAppear];
- _ MapView. delegate = self; // set nil when you do not need it here; otherwise, the memory will be released.
- }
- -(Void) viewWillDisappear :( BOOL) animated
- {
- [_ MapView viewWillDisappear];
- _ MapView. delegate = nil; // when not in use, set nil
- }
Shows the effect of compiling and running: