惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Schneier on Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Latest news
Latest news
H
Help Net Security
雷峰网
雷峰网
Spread Privacy
Spread Privacy
Cyberwarzone
Cyberwarzone
Project Zero
Project Zero
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
人人都是产品经理
人人都是产品经理
P
Privacy & Cybersecurity Law Blog
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed
U
Unit 42
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
S
Securelist
S
Security @ Cisco Blogs
T
Threatpost
P
Palo Alto Networks Blog
C
Check Point Blog
V
Vulnerabilities – Threatpost
T
Tailwind CSS Blog
B
Blog RSS Feed
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
P
Proofpoint News Feed
P
Privacy International News Feed
AWS News Blog
AWS News Blog
博客园 - 叶小钗
WordPress大学
WordPress大学

博客园 - 大洋

在asp.net 项目的bin目录中使用子目录 MVC项目引用备注 OAuth相关备注 手动安装windows的磁盘清理工具 在CentOS上安装 MongoDB CentOS 笔记 MongoDb 判断字段长度比较好的方法 MongoDb 出现配置服务不同步的处理 Silverlight 离线安装包 批量修改WORD表格属性 搭建高可用mongodb集群(四)—— 分片 如何稳定地使用 Google 搜索https://encrypted.google.com/ widows 2008 同步时间命令 MySql 初始化权限脚本 [转] windows下Svn服务器之必须提交修改注释篇 给编译好的DLL增加签名 Anychart 破解备注 Javascript 日期时间格式正则 MongoDB C# 操作备忘
Exiting an iOS App with Xamarin
大洋 · 2015-03-24 · via 博客园 - 大洋

referenced from: http://www.redbitdev.com/exiting-ios-app-with-xamarin-ios/

The team is in the middle of building an iOS app for iPad using Xamarin which will be enterprise deployed.  A requirement came up to automatically shut down the after a certain action was performed by the user.  Usually it’s recommended to not ‘kill’ your app on iOS and apps may fail certification if you do this.  Make sure to read the iOS documentation.

Now because we are doing an Enterprise Deploy and not an App Store Deploy, we have a few options and won’t fail any certification for using these techniques, but if you are going through the App Store certification process use at your own risk.

Crashing Your App

Our first attempt was to crash the app after showing a UIAlert notifying the user that the app will be shutting down. Wasn’t too thrilled about this procedure but to accomplish this, basically you just throw an exception.

1

2

3

4

5

6

7

public class ExitAppException : Exception

{

    public ExitAppException() { }

    public ExitAppException(string message) : base(message) { }

    public ExitAppException(string message, Exception inner) :

          base(message, inner) { }

}

Then just call

1

throw new ExitAppException("known crash to exit app");

Does what it needs to, but crashing your app to exit it is not the best way to make it happen.

Calling exit() Function

Next option is to P/Invoke the exit() function. To accomplish this using C# do the following

1

2

[DllImport("__Internal", EntryPoint = "exit")]

public static extern void exit(int status);

Then just call the function

Calling this may cause your app to fail App Store Certification and not the best user experience. It also will cause applicationWillTerminate and some UIApplicationDelegate methods to not be called. Here is an excerpt from iOS documentation

ios-warning

Using terminateWithSuccess

Third option is to call terminateWithSuccess which is a private method of (UIApplication *)sharedApplication.

Using Xamarin.iOS you basically have to use a Selector to call the private method as follows

1

2

3

4

5

6

7

8

9

static void TerminateWithSuccess ()

{

Selector selector = new Selector ("terminateWithSuccess");

UIApplication.SharedApplication.PerformSelector

    (selector, UIApplication.SharedApplication, 0);

}

TerminateWithSuccess();

Calling private methods is not allowed according to Apple certification guidelines and you will most likely get you rejected from the app store.

Using NSThread.exit

Last option is to call NSThread.exit from your main thread.

According to the documentation, you should avoid calling this because it doesn’t give you a chance to clean up or possibly save state.

So What to Use?!?

So typically in an iOS app you don’t usually ‘exit’ your app (same goes for Windows Phone and Android it’s a free for all) but there are sometimes situations where this is required. If you are creating an enterprise deploy app, you should be fine. If you are creating an app that will be put through the certification process, you may not pass with some of the options used. We have never had to use this ‘feature’ in an App Store app but my order in which I would try would be

  1. P/Invoke exit()
  2. NSThread.exit()
  3. throwing an exception
  4. terminateWithSuccess

Thanks go out to the Xamarin support team (specifically Brendan Zagaeski) for pointing the team in the right direction.