简体   繁体   English

Safari IOS 8的扩展

[英]Extension for Safari IOS 8

I am working on extension for safari.I have checked we can communicate between host app and extension as we can run extension or close extension.But in my case I want to communicate with host app without closing extension app. 我正在为野生动物园进行扩展。我已经检查了我们可以在主机应用程序和扩展程序之间进行通信,因为我们可以运行扩展程序或关闭扩展程序。

var MyExtensionJavaScriptClass = function() {};
MyExtensionJavaScriptClass.prototype = {
run: function(arguments) {
    arguments.completionFunction({"baseURI": document.documentElement.innerHTML});
 },

test: function(arguments) {

    alert("Need to run without closing extension");

},
finalize: function(arguments) {

    alert("Test Done");
    // arguments contains the value the extension provides in [NSExtensionContext completeRequestReturningItems:expirationHandler:completion:].
    // In this example, the extension provides a color as a returning item.
    document.body.style.backgroundColor = arguments["bgColor"];

}
};
var ExtensionPreprocessingJS = new MyExtensionJavaScriptClass;

In above my JavaScript file I have run function that run at the time of extension run and finalize fun run as we call completeRequestReturningItems in objc side.I want to run my test function without closing extension 在我的JavaScript文件上方,我有运行功能,该功能在扩展运行时运行,并在我们在objc端调用completeRequestReturningItems时确定运行的乐趣。我想在不关闭扩展名的情况下运行测试功能

You don't. 你不知道

To quote Apple's Extension Guidelines , from the section How an Extension Communicates. 要引用Apple的扩展指南 ,请参见扩展的通信方式部分。

There is no direct communication between a running extension and its containing app; 正在运行的扩展程序及其包含的应用程序之间没有直接通信; typically, the containing app isn't even running while its extension is running. 通常,包含应用的扩展程序在运行时甚至没有运行。

This isn't to say that you cannot, just that Apple doesn't want you, and the ability to do so is probably either private or non-existent. 这并不是说您不能,只是苹果公司不想要您,而这样做的能力可能是私人的,也可能是不存在的。

Quick terminology level set: 快速术语级别设置:

Containing App = "an app that contains one or more extensions is called a containing app" Host App = "An app that can let users choose an extension to help them perform a task is called a host app." 包含应用程序=“包含一个或多个扩展名的应用程序称为包含应用程序” Host App =“可以让用户选择扩展名以帮助他们执行任务的应用程序称为主机应用程序。”

That being said, Apple does not supply a communication stream from Host App to extension. 话虽如此,Apple并未提供从Host App到Extension的通信流。 In your case, you can load data initially with the run() in the JS Preprocessing file and then respond with data on exit of the extension with finalize(). 在您的情况下,您可以首先在JS Preprocessing文件中使用run()加载数据,然后在扩展名退出时使用finalize()响应数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM