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

时间:2015-03-13 03:43:23

标签: ios objective-c iphone

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

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

 #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

它给我的错误是:

ToolBelt WatchKit Extension/InterfaceController.m:22:21: 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead.
对于提出这样一个菜鸟问题,任何帮助都会非常遗憾

提前致谢

1 个答案:

答案 0 :(得分:2)

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