ios - 如何从处理 iPhone 上的应用程序中消失应用程序

标签 ios objective-c swift

enter image description here

有没有办法让 iPhone 上正在处理的应用程序消失? 就像下面这张照片。 例如App Store应用是我自己的应用。我想在双击主页按钮时让它消失。 感谢您的帮助!

最佳答案

如果你想杀死你的应用程序,你可以调用:

exit(0);

However the app will look like it crashed. Apple don't recommend calling this function

如果你想在风格上做到这一点,你必须在 UIApplication 类中使用一些未记录的方法。 将此添加到您的标题

@interface UIApplication (Private)
- (void)suspend;
@end

然后你就可以这样调用它了

//this will animate the app to home screening won't quit it 
[[UIApplication sharedApplication] suspend];

您可以在调用退出应用的方法后设置一个定时器

NSTimer* myTimer = [[NSTimer alloc] initWithFireDate:[NSDate date]                        
                                            interval:0.4                       
                                              target:self                        
                                            selector:@selector(suspendTimeout:)                        
                                            userInfo:nil                        
                                            repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];

- (void)suspendTimeout:(id)sender{
    exit(0);
}

关于ios - 如何从处理 iPhone 上的应用程序中消失应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37917453/

相关文章:

ios - 如何显示 UISearchBar 搜索的建议?

ios - UIView 在 UIScrollview 中不移动

ios - 水平 UIScrollView 自动布局约束本地化

iphone - 向单个 AVAudioPlayer 添加多首歌曲

ios - UIWebView 可以是 iOS 中的 "Buy Now"选项还是违反 TOS?

objective-c - 如何绘制自定义窗口控件(关闭、最小化和缩放按钮)

ios - 使用 NSTimer 和动画的 UIImageView 和 UILabel 的奇怪行为

ios - 在 Swift 3 中使用变量进行类型转换

ios - UIButton 框架不会随着使用 Swift 5 的可访问性大字体而增加

ios - NSXMLParser 的错误处理