2

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:

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

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

Phoneswapshop
  • 1,367
  • 8
  • 24
  • 47
  • possible duplicate of [App and Extension - Use Core data == error : sharedApplication()' is unavailable](http://stackoverflow.com/questions/26934888/app-and-extension-use-core-data-error-sharedapplication-is-unavailable) – Ken Y-N Mar 13 '15 at 03:46

1 Answers1

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.

Dex
  • 871
  • 4
  • 4