在后台打开带有URL的Safari应用程序,而不显示Safari界面 [英] Open the Safari app with URL in background without showing the Safari UI

查看:138
本文介绍了在后台打开带有URL的Safari应用程序,而不显示Safari界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Safari中从我当前的Cocoa应用程序中打开一个URL,但事情是我不想让用户看到Safari UI。即Safari应该在后台执行而不显示它发生了什么。
是否有可能?



如果是,请告诉方法。

方案

您可以使用 WebView 类在网络视图中打开网址,如果Safari不是强制性的,则不要让用户看到WebView



您可以使用脚本桥框架以最小化应用程序safari或使用头文件 Safari.h 中的其他方法在打开URL后在后台运行它。
您可以通过此链接了解更多关于脚本桥。对于您的任务,请按照以下步骤操作:



使用以下终端命令为safari生成头文件:

  sdef /Applications/Safari.app | sdp -fh --basename Safari 



现在,检查您的home文件夹或当前目录被执行以查看文件 Safari.h
拖动此文件并将其添加到您的项目。
将ScriptingBridge.Framework添加到您的项目中。



导入标题:



#import< ScriptingBridge / ScriptingBridge.h>



#importSafari.h



现在使用下面的代码在打开网址后隐藏safari:

 code> SafariApplication * sfApp = [SBApplication applicationWithBundleIdentifier:@com.apple.Safari]; 

SafariWindow * win = [[sfApp windows] objectAtIndex:0];
[win setVisible:FALSE];


I want to open a URL from my current Cocoa app in Safari, but the thing is that I don't want the Safari UI to be visible to user. i.e. Safari should be executed in background without showing what is happening in it. Is it possible ?

If yes please tell the method to do it.

解决方案

You may open the URL in a web view by using WebView class and don't make the WebView visible to user if safari is not a compulsory requirement.

OR

You may use Scripting Bridge framework to minimize the application safari or use other methods in header file Safari.h to run it in background after opening the URL. You may go through this link to know more about Scripting Bridge. For your task follow the steps below:

Generate a header file for safari, using the terminal command below:

   sdef /Applications/Safari.app | sdp -fh --basename Safari

Now, check your home folder or the current directory from which terminal cmd is executed to see a file Safari.h Drag this file and add it to your project. Add ScriptingBridge.Framework to your project.

Import headers:

#import <ScriptingBridge/ScriptingBridge.h>

#import "Safari.h"

Now use the below code to hide safari after opening the URL:

SafariApplication* sfApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.Safari"];

SafariWindow* win =  [[sfApp windows]objectAtIndex:0];
[win setVisible:FALSE];

这篇关于在后台打开带有URL的Safari应用程序,而不显示Safari界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆