-
-
Notifications
You must be signed in to change notification settings - Fork 53
Use STLocationRequest in objective-c ViewController #9
Comments
Hey JeanPierreFig, STLocationRequest is written from the ground up in Swift. To present the STLocationRequestController it uses an UIViewController Extension (found in the ReadMe). import STLocationRequest
func showLocationRequest(){
self.showLocationRequestController(
setTitle: "We need your location for some awesome features",
setAllowButtonTitle: "Alright",
setNotNowButtonTitle: "Not now",
setMapViewAlphaValue: 0.9,
setBackgroundViewColor: UIColor.lightGrayColor(),
setDelegate: self)
} The UIViewController Extension will load the ViewController from the embedded Storyboard. The Swift file STLocationRequestController which you initialized is only the class for the ViewController so there will be no ViewController loaded from the Storyboard if you not use the UIViewController Extension. So to make the Swift-Extension also be visible in an Objective-C project you should fork the project and the @obj tag before the Swift classes. For more information have a look at https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html I will also search for an easy solution and later will give that conversation an additional comment. |
ok Thank you |
Ok , I got it kinda working :)
The view does present normally with everything in place but then I get this error a few second after
|
hello Jean, |
Hey there, So I've added Objective-C support in the newest Release 0.2.2. But the problem is that CocoaPods is not converting the Swift Extension File to the STLocationRequest-Swift.h Bridging Header, which will be generated if you add "use_frameworks!" in your podfile. So a workaround would be to create a new Swift File in your project and add a bridging Header. And create a function with an parameter from type UIViewController and call the STLocationRequestController within the Swift File. But I will try to find out why CocoaPods isn't creating an Objective-C Interface for an Swift Extension. |
Good news for all Objective-C folks 👍 Please perform a With Version 1.0.1 you can now initialize an #import "ViewController.h"
@import STLocationRequest;
@interface ViewController () <LocationRequestDelegate>
@end
@implementation ViewController
-(void)showLocationRequestController{
STLocationRequest *locationRequest = [[STLocationRequest alloc] initWithViewController:self];
locationRequest.titleText = @"We need your location for some awesome features";
locationRequest.allowButtonTitle = @"Alright";
locationRequest.notNowButtonTitle = @"Not now";
locationRequest.mapViewAlphaValue = 0.9;
locationRequest.backgroundViewColor = [UIColor lightGrayColor];
locationRequest.delegate = self;
[locationRequest presentLocationRequestController];
}
This should fix all your problems in an Objective-C environment. |
Nice thanks man 👍 :) |
Hello I'm getting this error.
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
I have a felling that the storyboard view is not loading but I'm not sure.This is how I try to present the view
STLocationRequestController *request = [[STLocationRequestController alloc] init]; [request setTitle:@"test"]; [request setTitleLabelText:@"test"]; [request setAllowButtonTitle:@"Alright"]; [request setNotNowButtonTitle:@"eded"]; [request setMapViewAlphaValue: 0.9]; [request setBackgroundViewColor: [UIColor lightGrayColor]]; [self presentViewController:request animated:YES completion:nil];
The text was updated successfully, but these errors were encountered: