How to Just launch app from share extension without post popup in Swift?

僤鯓⒐⒋嵵緔 提交于 2020-01-23 06:10:56

问题


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.

What I did:

1) Added rules in info.plist

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

Screen short :

Please someone help me to fix this issue. Thanks

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

objective 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

Swift :

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
    })
}

回答1:


If you want to hide the dialog, you need to process data in viewDidLoad instead of didSelectPost, after that to redirect your app use this code:

           self.dismiss(animated: false, completion: {
               let _ = responder?.perform(selectorOpenURL, with: url)
               self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
            })

Be sure that you set all flags and url scheme.




回答2:


Add this in your share view controller. You're welcome.

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
    })
}


来源:https://stackoverflow.com/questions/51626406/how-to-just-launch-app-from-share-extension-without-post-popup-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!