我创建了一个app程序,只有几行代码,功能是打开safari,但是打不开,在xcode中的.xcodeproj中把沙盒关掉就可以打开safari了。
![示例图片](https://i-blog.csdnimg.cn/blog_migrate/3954fd0a1567f8f68a890aae220f3d9e.png)
代码为
//
// AppDelegate.m
// NSTaskPractice2
//
// Created by Chen Xiaohan on 2021/5/10.
//
#import "AppDelegate.h"
@interface AppDelegate ()
@property (strong) IBOutlet NSWindow *window;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
//我写的代码---start-------------
//功能为使用task打开safari
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/Applications/Safari.app/Contents/MacOS/safari"];
[task launch];
//---------------end----------
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end