Skip to content

Commit

Permalink
Merge pull request #28 from mapbox/1ec5-objc-17
Browse files Browse the repository at this point in the history
Add support for bridging to Objective-C
  • Loading branch information
1ec5 committed May 16, 2016
2 parents 0dfb53b + 75ccda5 commit 9a62d2a
Show file tree
Hide file tree
Showing 19 changed files with 778 additions and 189 deletions.
6 changes: 6 additions & 0 deletions Example/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@end
16 changes: 16 additions & 0 deletions Example/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[ViewController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}

@end
4 changes: 4 additions & 0 deletions Example/ViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@end
46 changes: 46 additions & 0 deletions Example/ViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#import "ViewController.h"

@import CoreLocation;
@import MapboxStatic;

// You can also specify the access token with the `MGLMapboxAccessToken` key in Info.plist.
static NSString * const AccessToken = @"pk.eyJ1IjoianVzdGluIiwiYSI6IlpDbUJLSUEifQ.4mG8vhelFMju6HpIY-Hi5A";

@interface ViewController ()

@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
self.imageView.backgroundColor = [UIColor blackColor];
[self.view addSubview:self.imageView];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

MBSnapshotOptions *options = [[MBSnapshotOptions alloc] initWithMapIdentifiers:@[@"justin.tm2-basemap"]
centerCoordinate:CLLocationCoordinate2DMake(45, -122)
zoomLevel:6
size:self.imageView.bounds.size];
CLLocationCoordinate2D coords[] = {
CLLocationCoordinate2DMake(45, -122),
CLLocationCoordinate2DMake(45, -124),
};
MBPath *path = [[MBPath alloc] initWithCoordinates:coords count:sizeof(coords) / sizeof(coords[0])];
options.overlays = @[path];
MBSnapshot *snapshot = [[MBSnapshot alloc] initWithOptions:options accessToken:AccessToken];
__weak typeof(self) weakSelf = self;
[snapshot imageWithCompletionHandler:^(UIImage * _Nullable image, NSError * _Nullable error) {
typeof(weakSelf) strongSelf = weakSelf;
strongSelf.imageView.image = image;
}];
}

@end
8 changes: 8 additions & 0 deletions Example/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Loading

0 comments on commit 9a62d2a

Please sign in to comment.