我添加以下代码:
- (IBAction)done {
// Return any edited content to the host app.
// This template doesn't do anything, so we just echo the passed in items.
NSURL *url = [NSURL URLWithString:@"lister://today"];
[self.extensionContext openURL:url completionHandler:^(BOOL success) {
NSLog(@"fun=%s after completion. success=%d", __func__, success);
}];
[self.extensionContext completeRequestReturningItems:self.extensionContext.inputItems completionHandler:nil];
}
Run Code Online (Sandbox Code Playgroud)
在我创建Action Extension目标之后.但它无法奏效.
我的目的是:当用户在Photos.app(iOS的默认Photos.app或被调用的图库)中查看照片时,他点击分享按钮以启动我们的扩展视图.我们可以将Photos.app中的图像传输到我自己的应用程序,并在我的应用程序中处理或上传图像.
我也尝试"CFBundleDocumentTypes"但它也无法工作.
任何帮助将不胜感激.
我为我的应用添加了一个共享扩展名,例如SAMPLE(已存在于应用商店中),称为SAMPLESHARE.每当用户说拍照并试图分享它时,我希望他们通过Open In功能的视图控制器,而不是从Apple获得Post对话,基本上绕过它.所以我试图在共享扩展和我的应用程序之间分享图片,创建一个在应用程序和插件之间共享的应用程序组,然后将文件路径传递给我的应用程序的应用程序委托的openURL.
所以在我的主要应用代表中我有
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [[SAMPLEExternalFileHandler shared] handleExternalFileURL:url];
}
Run Code Online (Sandbox Code Playgroud)
如果我有一个需要打开不同流的URL文件路径,我基本上每次都会检查它.
在我的SHAREEXTENSION中,我有
#import "ShareViewController.h"
#import <MobileCoreServices/UTCoreTypes.h>
//Macro to hide post dialog or not, if defined, will be hidden, comment during debugging
#define HIDE_POST_DIALOG
@interface ShareViewController ()
@end
@implementation ShareViewController
NSUInteger m_inputItemCount = 0; // Keeps track of the number of attachments we have opened asynchronously.
NSString * m_invokeArgs = NULL; // A string to be passed to your AIR app with information about …Run Code Online (Sandbox Code Playgroud) I need to execute my host app from inside an extension. In Objective-C I've used this:
// Get "UIApplication" class name through ASCII Character codes.
NSString *className = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char []){0x55, 0x49, 0x41, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E} length:13] encoding:NSASCIIStringEncoding];
if (NSClassFromString(className))
{
// A different way to call [UIApplication sharedApplication]
id object = [NSClassFromString(className) performSelector: @selector(sharedApplication)];
// These lines invoke selector with 3 arguements
SEL selector = @selector(openURL:options:completionHandler:);
id (*method)(id, SEL, …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中添加一项功能,浏览网页的用户可以按链接上的“共享”,当正常的应用程序出现时,如“消息”、“邮件”、“Instagram”等,他们可以看到我的应用程序,当他们点击它时,我想处理我的应用程序内的网址。
我尝试过搜索:“swiftui 添加从 safari 到应用程序的链接”,但我只能找到处理 deepLinks 的方法onOpenURL
我假设根据我分享这些应用程序之一的链接时获得的经验,我必须为 SwiftUI 应用程序构建一个扩展?
我想知道是否有任何解决方案,或者我是否使用错误的术语来搜索这个问题。
任何帮助将不胜感激,谢谢!
我正在尝试调用一个带有多个(2+)参数的选择器(可以确定参数的数量).但是,选择器在编译时是未知的(实际上是使用NSSelectorFromString生成的).
在Objective-C中,我可以创建一个调用并为其设置参数并调用它.但这在Swift中不可用.有没有办法解决?喜欢:
let obj = SomeClass()
let selector = NSSelectorFromString("arg1:arg2:arg3:") //selector, arguments known only at runtime
//invoke selector
Run Code Online (Sandbox Code Playgroud) 我正在使用此处提供的解决方案从共享扩展中打开我的包含.它似乎没有使用任何私有API方式来做到这一点尽管它是脆弱的.
如果我使用它,Apple会拒绝我的应用吗?任何人都有一个批准的应用程序打开包含分享扩展的应用程序?如果是这样,做正确的方法是什么?
任何指针都很受欢迎.
ios ×6
swift ×2
ios15 ×1
ios8 ×1
nsinvocation ×1
objective-c ×1
selector ×1
swift3 ×1
swiftui ×1
xcode ×1