如何让UIWebView获取当前GPS位置

4
我在我的应用程序中有一个UIWebView,它加载了一个网站,该网站试图获取用户的当前GPS位置。在Safari中,它会弹出一个窗口询问是否要向该网站提供您的当前位置,但在我的UIWebView中却没有任何反应,我的网站无法获取用户的GPS位置。我该如何解决这个问题?我是iOS开发的新手,如果这很容易做到,请耐心等待,但我迄今为止找不到示例。

这是我目前所拥有的:

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {

    IBOutlet UIWebView *_webView;
}

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [_webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"http://google.com"]]];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)goBack:(id)sender {
    if ([_webView canGoBack]) {
        [_webView goBack];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

请参考类似的问题:https://dev59.com/6m855IYBdhLWcg3wxHYq - iOS Dev
这很相似,但这并没有告诉我我的UIWebView将如何访问此信息,只是告诉了我一般的位置获取方式。但我想让我的UIWebView正常工作 :-) - Petros Mastrantonas
@PetrosMastrantonas 你有这个答案吗?我想要类似的功能。 - Qasim Ali Khan
1个回答

0

编辑您的应用程序的 info.plist,并设置

NSLocationWhenInUseUsageDescription "您想解释为什么需要位置的字符串。"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接