Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bridging to Objective-C #28

Merged
merged 3 commits into from
May 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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