Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Use STLocationRequest in objective-c ViewController #9

Closed
JeanPierreFig opened this issue May 19, 2016 · 7 comments
Closed

Use STLocationRequest in objective-c ViewController #9

JeanPierreFig opened this issue May 19, 2016 · 7 comments

Comments

@JeanPierreFig
Copy link

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];

@SvenTiigi
Copy link
Owner

SvenTiigi commented May 19, 2016

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.

@JeanPierreFig
Copy link
Author

ok Thank you

@JeanPierreFig
Copy link
Author

Ok , I got it kinda working :)

 [self showLocationRequestControllerWithSetTitle:@"ejbd" setAllowButtonTitle:@"djej" setNotNowButtonTitle:@"dej" setMapViewAlphaValue:.9 setBackgroundViewColor:[UIColor lightGrayColor] setDelegate:self];

The view does present normally with everything in place but then I get this error a few second after

'NSInvalidArgumentException', reason: '-[ViewController locationRequestControllerPresented]: unrecognized selector sent to instance 0x7fc923db9220'

@blolo
Copy link

blolo commented May 27, 2016

hello Jean,
How did you solve this issue? I'm trying to add this library into my objective c code but its failing in located the delegate or the showLocationRequestControllerWithSetTitle method, thanks.

@SvenTiigi
Copy link
Owner

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.

bildschirmfoto 2016-05-30 um 19 42 34

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.

@SvenTiigi
Copy link
Owner

Good news for all Objective-C folks 👍

Please perform a pod update on your project so that STLocationRequest Version 1.0.1 will be installed.

With Version 1.0.1 you can now initialize an STLocationRequest Object in the following way (It also can be found in the ReadMe file).

#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.

@JeanPierreFig
Copy link
Author

Nice thanks man 👍 :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants