在我的Apple Watch应用程序中无法使用“共享应用程序”

时间:2021-03-16 01:21:49

hello I am working a a app for apple watch and my app has a button and i want when the button is clicked to open safari on the paired iPhone i'm new to iOS development so heres what i have so far:

你好我正在为苹果手表开发一个应用程序,我的应用程序有一个按钮,我想要点击按钮在配对的iPhone上打开safari我是iOS开发的新手,所以到目前为止我所拥有的:

InterfaceController.h

InterfaceController.h

//
//  InterfaceController.h
//  ToolBelt WatchKit Extension
//
//  Created by Chris on 3/12/15.
//  Copyright (c) 2015 Chris. All rights reserved.
//

#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>

@interface InterfaceController : WKInterfaceController
-(IBAction) internetbttn;

@end
@interface ViewController : UIViewController< UIWebViewDelegate >

@end 

InterfaceController.m

InterfaceController.m

 #import "InterfaceController.h"


@interface InterfaceController()

@end


@implementation InterfaceController


-(IBAction) internetbttn: (id)sender {
    NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
    [[UIApplication sharedApplication] openURL:url];

}

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];


}

- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user
    [super willActivate];
}

- (void)didDeactivate {
    // This method is called when watch view controller is no longer visible
    [super didDeactivate];
}

@end

the error its giving me is this:

它给我的错误是这样的:

ToolBelt WatchKit Extension/InterfaceController.m:22:21: 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.

any help would be amazing sorry for asking such a rookie question

问这样一个菜鸟问题会有什么帮助

Thanks in advance

提前致谢

1 个解决方案

#1


2  

As the error message indicates, the UIApplication class is unavailable from extensions (including WatchKit extensions). It is not possible to open a URL on the user's phone from a WatchKit extension. You should consider adopting Handoff to give the user a quick means to transition from your Watch app to your phone app.

如错误消息所示,UIApplication类不可用于扩展(包括WatchKit扩展)。无法从WatchKit扩展程序打开用户手机上的URL。您应该考虑采用Handoff来为用户提供从Watch应用程序过渡到手机应用程序的快速方法。

#1


2  

As the error message indicates, the UIApplication class is unavailable from extensions (including WatchKit extensions). It is not possible to open a URL on the user's phone from a WatchKit extension. You should consider adopting Handoff to give the user a quick means to transition from your Watch app to your phone app.

如错误消息所示,UIApplication类不可用于扩展(包括WatchKit扩展)。无法从WatchKit扩展程序打开用户手机上的URL。您应该考虑采用Handoff来为用户提供从Watch应用程序过渡到手机应用程序的快速方法。