IOS7 (Baidu map API Environment Construction)

Source: Internet
Author: User

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
  1. # Import "BMapKit. h" // import BMapKit. h
  2. @ Interface AppDelegate: UIResponder {
  3. BMKMapManager * _ mapManager; // instantiate
  4. } 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
    1. -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
    2. {
    3. // To use Baidu map, start BaiduMapManager first
    4. _ MapManager = [[BMKMapManager alloc] init];
    5. // If you want to pay attention to network and authorization verification events, set the generalDelegate parameter.
    6. BOOL ret = [_ mapManager start: @ "Your applied ak" generalDelegate: nil];
    7. If (! Ret ){
    8. NSLog (@ "manager start failed! ");
    9. }
    10. Self. window = [[[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds] autorelease];
    11. // Override point for customization after application launch.
    12. Self. viewController = [[[ZYViewController alloc] initWithNibName: @ "ZYViewController" bundle: nil] autorelease];
    13. Self. window. rootViewController = self. viewController;
    14. [Self. window makeKeyAndVisible];
    15. Return YES;
    16. }

      8. Add the following code to viewcontroller. m to display the map:

      [Plain]View plaincopy
      1. # Import "ViewController. h"
      2. # Import "BMKMapView. h"
      3. @ Interface ViewController ()
      4. @ End
      5. @ Implementation ViewController
      6. -(Void) viewDidLoad
      7. {
      8. [Super viewDidLoad];
      9. BMKMapView * mapView = [[BMKMapView alloc] initWithFrame: CGRectMake (0, 0,320,460)];
      10. Self. view = mapView;
      11. }
        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
        1. (Void) viewWillAppear :( BOOL) animated
        2. {
        3. [_ MapView viewWillAppear];
        4. _ MapView. delegate = self; // set nil when you do not need it here; otherwise, the memory will be released.
        5. }
        6. -(Void) viewWillDisappear :( BOOL) animated
        7. {
        8. [_ MapView viewWillDisappear];
        9. _ MapView. delegate = nil; // when not in use, set nil
        10. }

          Shows the effect of compiling and running:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.