Toggling AirPlane mode in iOS Programmatically

五迷三道 提交于 2019-11-27 13:45:19

Every single App Store app is sandboxed with entitlements.

What you are trying to achieve is simply not possible if you want to distribute your app in the App Store. Your App simply cannot get enough privileges to achieve anything remotely similar. You cannot set global settings that changes the behaviour of the system. Apple will never allow that.

At the best you can monitor the status of the network connectivity via reachability but this is pretty much it. Using private API = straight app rejection.

If you don't care about AppStore submission and if your device is jailbroken (up to iOS 7.0.4 are jailbreakable), then you can follow these steps in exact order to programatically turn on or off Airplane Mode. I am also attaching a sample project to make things easier.

  1. Download (https://iosopendev.googlecode.com/files/iOSOpenDev-1.6-2.pkg) and install. This will install the necessary tools in order to directly install the app in the place where Apple's apps are located. This is needed so that you have a proper access and permission.

  2. Install OpenSSH in your device using Cydia. Then follow this tutorial: (http://www.priyaontech.com/2012/01/ssh-into-your-jailbroken-idevice-without-a-password/) to enable access without password (Using SSH key).

  3. Download the sample project I created from here: (https://www.dropbox.com/s/c0i76vmtfckvsut/ToggleAirplane.zip) This project uses the same entitlements as SpringBoard app (App that controls home screen) of Apple. So you will have access to every setting. You will only need to know how to call it programatically.

  4. In build settings go to "User Defined" section and edit the value for key iOSOpenDevDevice to the IP address of your device.

  5. Now most awesome part. Press Command + Shift + I. This will install and respring your device.

  6. However you may not see the app. To see it, download the Respring app from Cydia. When you launch it, it will respring the device. You should be able to see the app "ToggleAirplane" on your home screen.

Note: You won't be able to delete it from home screen just like you cannot do with Apple's apps. To delete it, you will need to go to Cydia->Packages. Fine the app and uninstall.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!