Ios Objective-c mac应用程序-打开外部URL
我正在尝试打开一个外部链接:google.com,但我不能,有人能说出我在代码中做错了什么吗 有人可以解释为什么默认情况下会阻止外部链接 AppDelegate.mIos Objective-c mac应用程序-打开外部URL,ios,objective-c,Ios,Objective C,我正在尝试打开一个外部链接:google.com,但我不能,有人能说出我在代码中做错了什么吗 有人可以解释为什么默认情况下会阻止外部链接 AppDelegate.m #import "AppDelegate.h" #import <WebKit/WebKit.h> @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; @property (weak) IBOutlet WebView *web
#import "AppDelegate.h"
#import <WebKit/WebKit.h>
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet WebView *webview;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
NSURL*url=[NSURL URLWithString:@"HTML/content.htm"];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
NSURL*url = [[NSURL alloc]initWithString:@"http://google.com/" ];
[[UIApplication sharedApplication] openURL:url];
NSURL *htmlFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HTML/content" ofType:@"htm"] isDirectory:NO];
request = [NSURLRequest requestWithURL:htmlFile];
[[self.webview mainFrame] loadRequest:request];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
return YES;
}
@end
#导入“AppDelegate.h”
#进口
@接口AppDelegate()
@属性(弱)窗口*窗口;
@属性(弱)IBOutlet WebView*WebView;
@结束
@实现AppDelegate
-(无效)ApplicationIDFinishLaunching:(NSNotification*)通知{
[[NSApplication sharedApplication]激活其他应用程序:是];
NSURL*url=[NSURL URLWithString:@“HTML/content.htm”];
NSURLRequest*request=[nsurlRequestRequestWithURL:url];
NSURL*url=[[NSURL alloc]initWithString:@”http://google.com/" ];
[[UIApplication sharedApplication]openURL:url];
NSURL*htmlFile=[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@“htm”类型的“HTML/content”是目录:否];
request=[NSURLRequest requestWithURL:htmlFile];
[[self.webview mainFrame]加载请求:请求];
}
-(无效)申请将终止:(NSNotification*)通知{
//在此处插入代码以删除应用程序
}
-(BOOL)应用程序应在最后一个窗口关闭后终止:(n应用程序*)应用程序{
返回YES;
}
@结束
它被标记为iOS,标题为Mac,使用NSWindow
,NSApplication
。。。webview
nil吗?你的代码中有两个NSURL*url
,你真正的代码是什么?一个我用来打开内部url,所以我尝试创建另一个来打开外部url,有意义吗?你试过编译你的代码吗?你不能在Mac app中使用UIApplication引用。如果你在Xcode 7上遇到“app Transport Security has blocked”这样的错误,你应该在info.plist中插入一行新行,如下所示:“app Transport Security Settings”,其同级项“Allow Arbital Loads”必须设置为true。希望这有帮助。