How do I profile an iOS application startup from push notification? - ios

I want to profile my iOS app when it starts up from the user swiping a push notification, from the not-running state.
How do I set up Instruments to attach to a particular app as soon as it starts up on the device (as opposed to starting the app via the "Profile" button in Xcode)?

You can change the process target in Instruments to "All Processes" on the device and then filter down to just your app.
I named my example app test in the screenshot above.

Related

In what cases can an app run after device reboot but before the user unlocks the device?

We are developing an app that can receive silent push notifications. Upon receiving the notifications, the app gets put into the background and executes some code. During this code execution the app needs to access an item in the keychain that is protected with the protection level kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly. According to this SO post (Does iOS start app in background after reboot if remote-notification defined in UIBackgroundModes and new push notification comes?) and Apple's app lifecycle diagram, an app is in the not-running state after a device reboot and can therefore not be put into the background until the user has launched it into the foreground at least once.
However, Apple also provides the protection level kSecAttrAccessibleAlways. If an app can only run in the background after it has first launched, what's the purpose of the kSecAttrAccessibleAlways attribute? Wouldn't the user first have to unlock the device in order for the app to be able to run in the background? In what cases can apps run after a device reboot but before a user has unlocked the device? Apple also provides the protection level NSFileProtectionCompleteUntilFirstUserAuthentication for files in the app's sandbox container. In what situations would apps even be able to attempt to access their files before a user has unlocked the device after a reboot? Any insight into this is greatly appreciated, thank you.

iOS 7 Single App Mode Change Device Settings

I have a an iOS7 app running in a Single App Mode on an iPad.
The device is put in the Single App Mode via Apple Configurator.
The Single App mode does not respond to the Home Button.
Is there a way a user can access the device settings when running in a Single App Mode (For example change device brightness or turn bluetooth ON)
Short answer is no.
A device running in single app mode will not allow the user to exit the app to access settings.
A possible solution is to use the Restrictions configuration payload with the autonomousSingleAppModePermittedAppIDs key set to the bundle id for your app.
You will need to install a configuration profile either manually or through an MDM with this payload on the device.
Once the profile is installed your app you can enter single app mode programmatically by calling UIAccessibilityRequestGuidedAccessSession.
You can now add some UI (like a button) to permit the user to exit guided access and launch settings, you exit guided access using the same API to enter it.
Note: This won't force the user back to your app once they have exited your app. You will have to find some other way to do that (ugly hack: force install another configuration profile that brings your app back into single app mode, once that has happened, remove this profile but leave the one permitting it to request guided access).

Blackberry background Push Notification using MDS

I am working on Blackberry Push Notification using MDS. I have referred the sample project HTTPPushDemo which Blackberry API has provided. I am getting pushed data successfully only when app is running. How I will get pushed notification using MDS when app is not running ?
The typical arrangement is to have two apps - the foreground app and the background app. The foreground app has all the UI elements, and it starts when the user clicks on the app icon on the device, and terminates when the user selects 'exit' This would largely be what you've written already.
The background app hides itself - no icon is present in the app switcher or on the device. This means the background app continues to run whether or not the foreground app is running. This allows you to setup the push listener, and keep it running even when your app is "not running"
Both 'apps' actually inhabit the same codebase - you differentiate them by adding a new start argument, and then in the app startup, the code checks whether it should be the foreground or background app, and behaves appropriately.

Can I set an application to launch everytime iOS device is unlocked?

Is it possible to set a certain iOS app (with whatever necessary user permissions) to launch automatically each time the phone is unlocked?
No. The only ways to start an app are:
from the springboard
through a user acting on a local or push notification posted by your app
from another app using an URL scheme
Not one that will make it to the appstore...

Debugging App When Launched by Push Notification

I am currently developing an app that receives Push Notifications. I have this all working 100% through a PHP page. There are several different types of push notifications my app can receive. The PHP handles this and sends different packets of information to my app which are all received just fine.
However, when the users "views" the notification and my app launches, I obviously want to take a different action than I would if the user just launched the app manually - and on top of that, different actions depending on the push notification type. I have got this working fine... structurally.
One of my push types is supposed to open a UIView that makes several connections to several different servers and negotiates data back and forth. This UIView works fine when, for example, triggered from the main menu - however when my push notification is triggering this UIView to appear, the socket connections are not acting as expected.
Now my question is not about the sockets, but more so - How do you debug such a problem?? From what I can tell (I am relatively new) when the app launched from a push notification there is no way to link that execution to the debugger / console / etc... I am having a very difficult time trying to debug the code using UIAlertViews, as there are many lines of communication back and forth between the various servers.
Any advice you have for me would be greatly appreciated.
In Xcode < 4.0 (for Xcode >= 4, see answer by delirus below), you can now configure Xcode to attach the debugger to the app after you launch it, instead of launching the app through the debugger. This lets you debug things that vary based on the launch state of your application, such as URL schemes, pasteboards, and push notifications.
In Xcode look in the Source bar, and below Targets there will be Executables.
Bring up the inspector for your app in executables.
Click on the Debugging tab tab in the inspector.
Uncheck "Start executable after starting debugger"
Check the "Wait for next launch/push notification"
Now when you click debug from Xcode instead of launching the app a window will display telling it is waiting for the app to launch. You then launch the app normally on the phone and Xcode attaches to it
For Xcode 4 you have to:
Edit your active scheme via
"Schemes" dropdown. (⌘+<)
Than choose your product - 'Run
MyApp.app' on the left.
Select 'Info' tab on the right.
And finally choose "Wait for
MyApp.app to launch" option.
More here in "Customize Executables in the Scheme Editor" section.
EDIT:
In case you miss logs in GDB, see Louis Gerbarg's comment to his answer.
For Xcode 10, 9, 8, 7 & 6:
Select the Scheme on the toolbar (just left of the device you're debugging with)
Choose Edit Scheme
Select Run in the left panel
For the Launch option, select Wait for executable to be launched
Close the Scheme Editor and Run your Xcode project
Now you can debug when launching from a notification, custom url or by touching the app icon.
I'm not working with push notifications, so I don't know the exact working of push notifications. However, I'd try mimicking the receipt of a push notification by letting the main method of your program pretend a notification was posted if possible, or calling the application:didFinishLaunchingWithOptions: UIApplicationDelegate method from within the applicationDidFinishLaunching: method.
HTH - Cheers, Daan
In Xcode 6:
connect iPhone to Macbook with USB
launch the app on the iPhone by tapping the icon
In Xcode menu, Debug > Attach to Process > Pick your App
For Xcode 11 and 10, you can do the following:
Select Scheme option.
Choose Edit Scheme.
Select Run option from the left panel
In the launch part, select wait for executable to be launched, then close the dialog.
Build and run the project. You can now launch the app either by tapping the app icon, or by tapping on the notification message.

Resources