-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from mapbox/1ec5-objc-17
Add support for bridging to Objective-C
- Loading branch information
Showing
19 changed files
with
778 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface ViewController : UIViewController | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); | ||
} | ||
} |
Oops, something went wrong.