15

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 :

enter image description here 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
    })
}
Tushar Lathiya
  • 940
  • 9
  • 26

5 Answers5

2

calling the completion on request from viewDidLoad should be sufficient

override func viewDidLoad() {

    super.viewDidLoad()
    ⋮
    // custom logic
    ⋮
    self.extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
}
ha100
  • 1,563
  • 1
  • 21
  • 28
2

Do this from viewDidLoad, but you need to set a small timer, otherwise it won't work:

override func viewDidLoad() {
    super.viewDidLoad()
    Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(self.didSelectPost), userInfo: nil, repeats: false)
  }
Lenka Pitonakova
  • 979
  • 12
  • 14
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.

isHidden
  • 860
  • 5
  • 16
1

If someone got any problems how to hide this pop up window, I had the SLComposeServiceViewController type in my VC. Remove this type and add the normal UIViewController and the Pop up Window doesn't pop up anymore.

Make also sure create a new VC in the storyboard and change the initial VC to it.

Mobias
  • 31
  • 3
-3

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
    })
}
726a
  • 89
  • 9
  • my app is not opening..can you tell me how to open it – Tushar Lathiya Aug 01 '18 at 09:01
  • This just seems to hide the dialog box. That won't help much, when the user has to tap "post" on it – Nicolai Harbo Oct 10 '18 at 11:08
  • I answered this because the first question was about hiding the pop-up. There are online resources in Objective-C on how to launch it right away without tapping "post" you just have to make it in swift which is easy and I don't think I should be the one doing it. Thank you. – 726a Oct 11 '18 at 07:40
  • Question is bout how to open containers app from share extension. – Bhavesh.iosDev Sep 14 '19 at 13:58