我是 iOS 应用程序开发的初学者,我想通过从另一个应用程序复制链接来启动我的应用程序。单击它添加共享扩展,它显示弹出窗口。 但我的要求是它不应显示弹出窗口并在单击我的共享扩展程序时直接打开我的应用程序。
我做了什么:
1) 在 info.plist 中添加规则
<dict>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
屏幕短片:
更新:添加以下代码后弹出窗口没有出现,但我的应用程序没有打开
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
})
}
最佳答案
根据 viewDidLoad 的请求调用完成应该足够了
override func viewDidLoad() {
super.viewDidLoad()
⋮
// custom logic
⋮
self.extensionContext?.completeRequest(returningItems: [], completionHandler: nil)
}
关于ios - 如何仅从共享扩展启动应用程序而无需在 Swift 中弹出弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51626406/