我正在尝试为我的应用程序创建共享扩展,这需要从扩展程序登录Google.我已经设置了共享组密钥链,并且能够从主应用程序写入并读取扩展目标.但我无法从扩展程序登录Google,因为GIDSignIn.sharedInstance().hasAuthInKeychain()始终返回false.
有没有办法从扩展程序登录Google,我该怎么做?任何帮助,将不胜感激.
想象一下 iOS/Android 上的网页能够共享文件(使用Web Share API通过 Safari 共享扩展与自定义请求内容
\n我\xe2\x80\x99m 正在寻找一种可靠的方法来获取从 Safari 共享扩展返回到网页的响应(假设是任意 JSON)。
\n我已经尝试过但失败的选项:
\n我想要的是
我正在尝试实现以下用户流程:
我尝试了什么
我通过Xcode进行了Share扩展.这NSExtension是我的部分info.plist:
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>test</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
Run Code Online (Sandbox Code Playgroud)
这是test.js文件:
var GetURL = function() {};
GetURL.prototype = {
run: function(arguments) {
arguments.completionFunction({"URL": document.URL});
}
};
var ExtensionPreprocessingJS = new GetURL;
Run Code Online (Sandbox Code Playgroud)
我期望得到以下结果:在viewDidLoad方法中extensionContext?.inputItems将为我提供几个输入项,通过它我将能够获得所选内容和Web URL.
出了什么问题
在viewDidLoad方法中,extensionContext?.inputItems我只提供了一个项目 - 所选内容的纯文本表示(即使我同时选择了图像和文本).我可以使用纯文本,但我需要网页网址.
我的问题
如何在iOS Safari中使用共享扩展程序通过上下文菜单共享所选内容时,如何获取已打开网页的URL?
有没有人知道如何从应用扩展程序的视图控制器启动父应用程序?
我只想从其应用扩展程序启动主应用程序.
我已为我的主机应用和共享扩展设置了应用组.标识符看起来像"group.com.abc.xyzApp".有没有办法以编程方式获取此字符串?此外,如何检测是否以编程方式设置应用程序组?是否尝试使用应用程序组标识符初始化文件容器或用户默认值足以知道?例如:
[[NSUserDefaults alloc] initWithSuiteName:@"group.com.abc.xyzApp"].
当我从Photo库共享图像以从Photo App获取图像时,我使用了解决方案表单iOS Share Extension问题.这在模拟器中运行良好,但在设备上我收到错误,我无法访问itemProvider提供的NSURL:
2018年2月18日12:54:09.448148 + 0100 MyApp的[6281:1653186] [缺省] [ERROR]无法确定是否URL的/ var /移动/媒体/ PhotoData/OutgoingTemp/554581B2-950C-4CFD-AE67-A2342EDEA04D/IMG_2784.JPG由文件提供程序管理
由法令引起的:
[itemProvider loadItemForTypeIdentifier:itemProvider.registeredTypeIdentifiers.firstObject options:nil completionHandler:^(id<NSSecureCoding> item, NSError *error) {
}
Run Code Online (Sandbox Code Playgroud)
搜索项目名称的PHAsset不是一个好的解决方案,因为用户必须再次访问照片库.
我正在创建一个共享扩展程序,以允许将Youtube视频共享到我的应用中,并且很难顺利呈现自定义UI。我想代替默认的仅包含原始Youtube URL的视图控制器,而是要做类似于Facebook扩展的视觉效果,显示缩略图和视频标题。我的第一个尝试是编辑MainInterface故事板ShareViewController,但这样做简短地显示了我的自定义界面,然后默认UI布局将其“覆盖”。所以我最终将另一个带有UI的视图控制器添加到情节提要中,并在ShareViewController中添加了
override func presentationAnimationDidFinish() {
super.presentationAnimationDidFinish()
DispatchQueue.main.async {
self.pushConfigurationViewController(customVC)
}
Run Code Online (Sandbox Code Playgroud)
显然,这样做的问题在于,在推送自定义控件之前,我仍然可以看到默认的View Controller。因此,问题将是启动共享扩展名后如何立即显示我的自定义UI?我已经在.plist中尝试了NSExtensionPrincipalClass,但是没有任何积极的结果
提前致谢
我创建了一个macOS ShareExtension,我想用它来上传图片.
我还在测试这个,所以任何请求都会发送到https://beeceptor.com.
共享扩展工作正常,一旦我运行它就显示在预览中:
我添加一些文字并点击"发布"
但是图像没有上传.这是启动后台上传的代码:
let sc_uploadURL = "https://xyz.free.beeceptor.com/api/posts" // https://beeceptor.com/console/xyz
override func didSelectPost() {
// This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
let configName = "com.shinobicontrols.ShareAlike.BackgroundSessionConfig"
let sessionConfig = URLSessionConfiguration.background(withIdentifier: configName)
// Extensions aren't allowed their own cache disk space. Need to share with application
sessionConfig.sharedContainerIdentifier = "group.CreateDaily"
let session = URLSession(configuration: sessionConfig)
// Prepare the URL Request
let request = urlRequestWithImage(image: attachedImage, text: contentText)
// Create …Run Code Online (Sandbox Code Playgroud) 我正在调整一个应用程序来支持iPhone X.我有一个自定义视图控制器的共享扩展.我需要知道我的设备的安全区域插入,但是通过调用提供的safeAreaInsets方法在共享扩展中不可用,因为在那里不可见.有没有办法知道我的共享扩展中的属性值?UIWindowUIApplication.shared.keyWindowUIApplication.sharedsafeAreaInsets
在我开发的其中一个应用程序中,我使用共享扩展来导入钱包通行证 (PKPass)。
在 iOS 13(包括最新的 beta 8)上,当从 iOS 邮件应用程序中调用共享扩展时,该扩展没有接收到预期格式(URL)的数据。
这是来自共享扩展的 ShareViewController 的相关片段:
if let inputItems = self.extensionContext?.inputItems,
let inputItem = inputItems.first as? NSExtensionItem,
let attachments = inputItem.attachments,
let attachment = attachments.first,
attachment.hasItemConformingToTypeIdentifier("com.apple.pkpass" as String){
attachment.loadItem(forTypeIdentifier: "com.apple.pkpass" as String, options: nil) { data, error in
print ("data: \(String(describing: data))")
}
Run Code Online (Sandbox Code Playgroud)
在 iOS 12(最新版本)上,这也适用于 iOS 邮件应用程序中的附件(除了文件应用程序中的文件);data 包含一个可选的 URL。上面的打印语句在控制台中显示如下:
data: Optional(file:///var/mobile/Library/Mail/8EF174CF-68B9-414E-A166-D04C9DBE020E/INBOX.imapmbox/Attachments/13846/2/Attachment-1.pkpass)
Run Code Online (Sandbox Code Playgroud)
在 iOS 13 (beta 8) 上,在 iOS Mail 应用程序中,数据包含一个可选的 _NSItemProviderSandboxedResource。上面的打印语句在控制台中显示如下:
data: Optional(<_NSItemProviderSandboxedResource: 0x2839aa9e0>)
Run Code Online (Sandbox Code Playgroud)
这似乎只影响邮件应用程序。在“文件”应用程序中,数据按预期保留了一个 URL。
这是一个错误(实际上我已经在 beta 4 中使用反馈助手报告了这个问题)还是 iOS 13 引入的一些新的安全功能?在这种情况下,如何访问附件的 …
share-extension ×10
ios ×8
swift ×3
android ×1
ios11 ×1
ios13 ×1
iphone-x ×1
macos ×1
macos-mojave ×1
nsurlsession ×1
objective-c ×1