iOS Application - intercept when a user deletes the app from device - ios

I'm developing an apple iOS application using Xcode.
How to know if a user removed an application from his iPhone/iPad Device?
thank you

If you have several your apps on device - you can use SHARED KEYCHAIN to detect marker you've written in deleted app. Shared keychain can be accsessed by apps sharing same keychain access group. Or you can get approximate statistics using some statistics framework by checking whether some application stopped logging any events for a long period of time.

No you cannot. The only thing you can catch is first run of your app. There is no obvious reason for knowing when your app is uninstalled (except of spamming users). You can just keep stats to see your app usage if that's the case.

No, an app cannot detect when it is being deleted from the device.
An app runs in a sandbox / secure container. (Almost) everything outside that sandbox is just a 'mystery' for the app. Your app shouldn't need to know, so IF this is an issue at all, it is basically just a design issue for you to deal with.

Related

Force iOS app to open in foreground using private APIs

I'm currently working on a kiosk type application that won't be distributed on the App Store. The device will sometimes need to switch applications to handle some other tasks, but in the case where a user doesn't manually switch back, I need my app to come to the foreground after a set amount of time has passed.
We don't have control over the other apps, so getting them to switch to ours after a timeout isn't possible.
I know this can't be done through official means, but I'm asking if anyone knows of a private API I could call from within a scheduled notification that will foreground my application.
I have a feeling that this cannot be done without a jailbreak due to the sandboxing nature of the apps, as in, there's no way to send a message to whatever service launches apps on the device. Although it should be possible, as the demo devices in the Apple stores are able to revert back to a demo "screensaver" app if left alone for a while. What are they doing to achieve this?
If there is a jailbreak hack for this to work or a config or something an MDM service could handle, I'd be happy to try that out.
Again, this is for a private application that will not be distributed on the App Store. The app will be placed on devices located throughout our building and running on our internal network.
Via Jailbreak you could look at something like AutoLaunch:
If you use a particular app that seems to crash here and there, then a new free jailbreak tweak called AutoLaunch could be your next best friend. It can automatically re-launch any app that crashes on your device so you don’t have to re-launch it yourself.
http://www.idownloadblog.com/2017/01/08/autolaunch/
Not sure how much control you'd have over wanting to launch regardless of whether it's crashed or not. You might be able to ask the author to provide the source-code or work with him to get your desired result.
UPDATE:
It's open source:
https://github.com/chenzhijie/autolaunch
Upon further inspection of the source it looks like it uses the following to launch the application after a crash:
int createSubProcessResult = fork();
if(createSubProcessResult == 0) {
execl("/usr/bin/open","open",[currentAppBundleId UTF8String],NULL);
}
I guess you could roll your own version of Autolaunch and have it wait/subscribe for a remove command that'll launch/switch different apps.

Programmatically erase iPhone's data swift

I am developing an iPhone Application to wipe all data from iPhone including photos, videos, contacts, messages, apps, etc. programmatically. I wish to achieve this with an iPhone Application only.
The approach I am thinking of somehow I manage to Clear data from iPhone and rewrite the memory with some junk files or binary data 1010 say. (Its just an idea!)
All I have managed to do is delete photos from Photos which are further not deleted from Recently deleted folder in Photos App.
Also, I found this Programmatically How to wipe out iPhone or iPad data in i phone apps in i phone apps which declines it's feasibilty.
But, Is there a way to programatically restore my iphone to factory settings? says using the C files mentioned here https://github.com/lite/osxrce/blob/master/resetapp/main.m can may be make it possible. They say they tried it on a jailbroken device though.
What you are hoping to do isn't possible on an non-jailbroken iPhone. You will be violating the iOS sandboxing among other things.
A similar outcome may be possible by creating your own MDM server, and building your app to interface with it. On first installation of your app, you can have it install the MDM profile. The app can then feature your 'Wipe' button which can signal to the MDM to send a wipe push notification to the device.
It would take a lot more work that what you're asking about, but it should be possible.
Reference: https://developer.apple.com/enterprise/documentation/MDM-Protocol-Reference.pdf
Apple do not allow to delete files which aren't created or part of your application, so you will not be able to delete data of other apps.
I don't think you're allowed to do that anyway. Even if you were able to do it, it would not be accepted on the app store.
You can backup the iPhone via AppleMobileBackup.exe -b, then modify the according
database file(such as addresscontacts, messages), and restore the modified ituensbackup files to the iPhone via AppleMobileBackup.exe -r.

Auto restart iOS app for enterprise, not jailbroken

I'm currently developing an app using enterprise account for internal purposes only.
I heard something about daemon for jailbroken devices in order to make my app just like an android service.
Is there anything I can do when not jailbroken?
Maybe 3rd party framework or piece of codes? Maybe private framework?
Something like this maybe: Make the application restart by itself on a jailbroken device
But for non-jailbroken.
P.S. - The app of course is not for app store and could not be on app store.
I agree with Tander. But we have achieved almost similar effect using combination of SLC (Significant Location Change), Background fetch and Silent push notifications. Whole point is that app periodically trigger call to API to let know it is alive.
If this fails, we sent normal Push Notification. I was looking into this for fair amount of time and didn't come up with nothing better. But note that you get very limited process time to execute code using this options.
Unless the device is jail broken the short answer is no.

Is it possible to have a running background app on iOS

This is a strange one, I have a need to create an iOS app that runs in the background on an iOS device, but can not be visible on the Home screen of the device. The app may need to show up in Settings to configure a few options, but it mostly needs to run behind the scenes.
I do not need to publish this app on the app store, it is strictly an enterprise app for my company.
Does anyone know how this kind of behavior might be achieved? Configuration profiles? API's? etc?
Edit: Jailbreaking the device is not really an option for us. We have to keep the devices as they are.
Backgrounding
There are several methods to get permanent background execution:
a) Silent audio which is mentioned by JRG-Developer
b) Usage of beginBackgroundTaskWithExpirationHandler + turning location manager on/off (it will reset remaining time to 600 seconds)
Making app invisible
You can use SBAppTags in Info.plist (take a look at this: How to remove app icon programatically from jail broken iPhone app?)
It will make your icon not visible on Home screen.
I've no idea how you can tackle the not be visible on the home screen criteria, but there are certain services that are allowed to be run in the background continuously, notably:
Background Audio (even silent audio)
While this is indeed very hacky, short of jailbreaking the devices, this may be your best bet.
While it's unlikely / very difficult to get past the review process, in the event for some reason you do need to (attempt) to publish this app to the App Store, some apps are even available on the App Store which take advantage of this hack, such as PasteBot.
You should definitely read their write-up here about getting their app's Cut-and-Paste functionality to work while in the background:
http://tapbots.com/blog/pastebot/pastebot-music-in-background
Another out-of-the-box idea, why not use Android devices instead, which do support multitasking?
Two methods:
Jailbreak. A jailbroken iPhone is essentially a Mac and you can use all Mac UNIX programming tricks - spawn a daemon (you can even ask launchd to do that), or something. You can set up enteprise-wise Cydia source. Refer to saurik's website for a walkthrough and set up an experimental server using Ubuntu (which used apt too)
A non-jailbreak way may be possible, but it will depend on what your app is doing. You can try use enterprise-wise push notifications.
Given that this is impossible to do on non jailbroken phones, I'd suggest the following:
develop a directory app, or a phone list app, something that is specific to your company.
have it connect to a web service once a day to register the device ID (so you know the user has not deleted the app)
tell users they need to keep the app open at all times (and if a user's device does not register one day, send them an email asking them to launch the app).
Now you can send back whatever you want with the app. If they kill it, you'll know the next day when you have a script look at the logs.
If you think this is a terrible idea, it is, but its the best you are going to get on iOS right now.
EDIT: you could send a notification every day - say in the AM - to make sure the user opened the app if it wasn't running.
From my experince, this kind of behaviour cannot be achieved on iOS. When an app enters into background, it is active only for a small particular amount of time. After that, it goes into hybernate state. It stops working. So the behaviour you said can not be achieved without abusing iOS workflow. Thats why some call iOS's multitasking as not true multitasking. Only jailbreaking might help your case. That was for one case. The second one where the app cannot be seen on home screen is again, impossible. It has to be on springboard to run.

How do I programmatically remove an application from an iOS device? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Programmatically delete my own app
Currently I am working on a iphone application and one of the critical requirement of the application is if a user cannot successfully authenticate after 5 attempts, the application is removed from the user’s iPhone.
How can I achieve this goal?
Being able to alter things outside of the application's own sandbox is a huge security risk that Apple (understandably) has not allowed. Therefore you will not be able to do this. The best you can do is store the result in a persistent value and not allow to app to continue after launching. For bonus points, you can store this value in the iOS keychain so that it will persist between installs if you like, then the user will be forced to reset their ios device to factory defaults to be able to use it again.
Can't be done. The best you can do is to make your app stop functioning after five failed authentication attempts.
you cant. the only one who can have this privilige is the user. You could just make the app to not open anymore, making the user angry and then deleting it afterwards.
Its not possible. You should handle it programmatically like locking the application. Once user is failed for 5 attempts, change your startup viewcontroller and do not allow the user to navigate any where else. Here you can display some message to delete the app.
An application, installed in a non-jailbroken device, is a sandboxed eco-system.
If your app is for App Store, this thing cannot be done. If this app is for a JB device (for In-House apps would be possible, but I think you need root permissions to delete apps), try to remove the app file from disk after the app has gone on background (but I'm quite sure files are locked, so you'll not be able to do it). If this approach, as I guess, doesn't work due to locked files, you can try to search for private APIs.
It's not possible. You only solution is lock the app if authentication not success.

Resources