如何仅从共享扩展名启动应用程序而无需在Swift中弹出窗口? [英] How to Just launch app from share extension without post popup in Swift?

查看:77
本文介绍了如何仅从共享扩展名启动应用程序而无需在Swift中弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS应用程序开发的入门者,我想在另一个应用程序的复制链接上启动我的应用程序.单击时添加共享扩展名,它显示弹出窗口. 但我的要求是,它不应显示弹出窗口,而应在单击共享扩展名后直接打开我的应用程序.

I am a begginer in iOS app development and I would like to launch my app on copy link from another app. added shared extension on click it is displaying popup. But my requirement is it should not display popup and directly open my app on click of my shared extension.

我做了什么:

1)在info.plist中添加了规则

1) Added rules in info.plist

<dict>
    <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
    <integer>1</integer>
</dict>

短屏:

请有人帮我解决此问题. 谢谢

Please someone help me to fix this issue. Thanks

更新:添加以下代码后,弹出窗口不会出现,但我的应用无法打开

Update : After adding below code popup is not coming but my app is not opening

目标C:

    - (BOOL)isContentValid {
    return YES;
}
#ifdef HIDE_POST_DIALOG
- ( NSArray * ) configurationItems
{
    return @[];
}
#endif

- ( void ) didSelectPost
{
#ifdef HIDE_POST_DIALOG
    return;
#endif
}

CGFloat m_oldAlpha = 1.0;
#ifdef HIDE_POST_DIALOG
- ( void ) willMoveToParentViewController: ( UIViewController * ) parent
{
    m_oldAlpha = [ self.view alpha ];
    [ self.view setAlpha: 0.0 ];
}
#endif

#ifdef HIDE_POST_DIALOG
- ( void ) didMoveToParentViewController: ( UIViewController * ) parent
{
    // Restore the original transparency:
    [ self.view setAlpha: m_oldAlpha ];
}
#endif



#ifdef HIDE_POST_DIALOG
- ( id ) init
{
    if ( self = [ super init ] )
    {
        [ [ NSNotificationCenter defaultCenter ] addObserver: self selector: @selector( keyboardWillShow: ) name: UIKeyboardWillShowNotification    object: nil ];
    }

    return self;
}
#endif

#ifdef HIDE_POST_DIALOG
- ( void ) keyboardWillShow: ( NSNotification * ) note
{
    [ self.view endEditing: true ];
}
#endif

迅速:

override func isContentValid() -> Bool {
        // Do validation of contentText and/or NSExtensionContext attachments here
        return true
}
override func didSelectPost() {
        self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
    }
override func viewDidAppear(_ animated: Bool) {
    self.view.transform = CGAffineTransform(translationX: 0, y: self.view.frame.size.height)

    UIView.animate(withDuration: 0.25, animations: { () -> Void in
        self.view.transform = .identity
    })
}

推荐答案

根据ViewDidLoad的请求调用完成应该足够

calling the completion on request from viewDidLoad should be sufficient

override func viewDidLoad() {

    super.viewDidLoad()
    ⋮
    // custom logic
    ⋮
    self.extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
}

这篇关于如何仅从共享扩展名启动应用程序而无需在Swift中弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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