我目前正在开发一个专门针对iOS7的应用程序,它在菜单中打开了UIDocumentInteractionController,需要一个方法,当用户取消并且不选择可用选项时通知我。
UIDocumentInteractionControllerDelegate提供:
- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *) controller
但这并未指定用户是否点按了其中一个可用选项或取消。
有什么想法吗?
答案 0 :(得分:9)
注意:这不再适用于iOS 8,仅适用于iOS7及更早版本
要确定用户是否已取消菜单或选择了某个选项,您必须使用以下委托方法:
1-
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
didEndSendingToApplication:(NSString *)application
{
//get called only when the user selected an option and then the delegate method bellow get called
// Set flag here _isOptionSelected = YES;
_isOptionSelected = YES;
}
2-
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller
{
//called whether the user has selected option or not
// check your flag here
if(_isOptionSelected == NO) {
//the user has canceled the menu
}
_isOptionSelected = NO;
}
iOS 8
对于iOS 8及更高版本,请使用此方法代替步骤2中的方法:
- (void)documentInteractionController:(UIDocumentInteractionController *)controller
didEndSendingToApplication:(NSString *)application
答案 1 :(得分:0)
BOOL didSelectOptionFromDocumentController = NO;//**set this to "NO" every time you present your documentInteractionController too
-(void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application {
didSelectOptionFromDocumentController = YES;
}
-(void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
if (didSelectOptionFromDocumentController == NO) {//user cancelled.
}
}
答案 2 :(得分:0)
它不漂亮但它有效。
有谁能告诉我这是否会通过App Review?不确定,因为我指的是不可公开访问的类名(_UIDocumentActivityViewController)。 这是Swift 2.2!
NSObject Extension获取类名的字符串:
./configure --prefix=/usr/local/imagemagick/ -with-java-home=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.38.x86_64/
您从以下位置调用UIDocumentInteractionController的Viewcontroller:
extension NSObject {
var theClassName: String {
return NSStringFromClass(self.dynamicType)
}
}
答案 3 :(得分:0)
对于Swift 4,请使用:
func documentInteractionControllerDidDismissOpenInMenu(_ controller: UIDocumentInteractionController) {
// this function get called when users finish their work,
// either for sharing thing within the same app or exit to other app will do
}
我在用户将图像分享到Facebook和Instagram后使用它。