How to measure energy usage in Xcode 13 / iOS15? - instruments

I'd like to confirm the battery usage of an app I am developing on iOS, specifically on Xcode 13 and iOS 15. (Note: This app previously showed no issues with battery usage on previous versions of iOS.)
Previously, it seems that there were two ways to gather energy usage information:
#1. On the device under Settings > Developer > Logging
As per Apple's documentation described in the section titled "Log Energy Usage Directly on an iOS Device".
However, on iOS15, I can't find any options for logging under Developer or anywhere under settings even when searching.
#2. Profiling via Instruments using the "Energy Log" template
As per the same documentation from Apple described in the section "Use the Energy Diagnostics Profiling Template".
While it is still available in Xcode 12, this template is missing in Xcode 13. Naturally, it's also not possible to profile an iOS15 device with Xcode 12.
Digging through the Xcode 13 release notes, I found the following:
Instruments no longer includes the Energy template; use metrics reporting in the Xcode Organizer instead. (74161279)
When I access the Organizer in Xcode (12 or 13), select an app and click "Energy" for all versions of the app, it shows the following:
Apple's documentation for "Analyzing the Performance of Your Shipping App" says:
"In some cases the pane shows “Insufficient usage data available,” because there may not be enough anonymized data reported by participating user devices. When this happens, try checking back in a few days."
Well over a year into production and having sufficient install numbers, I have a feeling that waiting a few days might not do much.
I would like to determine if this is a bug in my app or a bug in iOS15. How can energy usage data be gathered using Xcode 13 on iOS 15?

After contacting Apple Developer Technical Support (DTS) regarding this issue, they provided me with the following guidance.
Regarding "insufficient usage data available" for energy logs accessible via the Xcode organizer:
DTS indicated that they do not publish the thresholds for active users and usage logs would be expected to be present if you have more that a few thousand active users consistently on each version of your app. If your app meets this criteria and still does not show energy logs, DTS recommended opening a bug report with them.
Regarding how to collect energy log data for your app:
DTS recommended using MetricKit to get daily metric payloads. Payloads are delivered to your app every 24 hours and it is then possible to consume them and send them off device.
The instantiation of this is vey basic and can be as simple as:
import MetricKit
...
// Somewhere in your application startup sequence:
MXMetricManager.shared.add(someObjectYouWantToHaveThisResponsibility)
...
extension SomeObjectYouWantToHaveThisResponsibility: MXMetricManagerSubscriber {
func didReceive(_ payloads: [MXMetricPayload]) {
for payload in payloads {
// Parse the payload here
}
}
}
For a full list of metrics, see the MXMetricPayload class.
Regarding the two documentation links that I included above:
Apple asked me to open feedback tickets in order to get them updated. I opened both tickets (FB9665186, FB9665194) on September 30, 2021 and they are both still in an "Open" status as of today.
In the case of my app and the problem I had encountered, it turns out that battery drain was just a symptom and not the actual problem, so it wouldn't be useful to include any of those details here.

Related

IOS Rejection the activity indicator spun indefinitely on launch, then no further action was generated at the time of review

Recently I submitted my App to App Store for review and get a rejection which says my App is loading forever:
Guideline 2.1 - Performance - App Completeness
We discovered one or more bugs in your app when reviewed on iPhone and
iPad running iOS 12 on Wi-Fi.
Specifically, the activity indicator spun indefinitely on launch, then
no further action was generated at the time of review.
Next Steps
To resolve this issue, please run your app on a device to identify any
issues, then revise and resubmit your app for review.
If we misunderstood the intended behavior of your app, please reply to
this message in Resolution Center to provide information on how these
features were intended to work.
For new apps, uninstall all previous versions of your app from a
device, then install and follow the steps to reproduce the issue. For
updates, install the new version as an update to the previous version,
then follow the steps to reproduce the issue.
Resources
For information about testing your app and preparing it for review,
please see Technical Note TN2431: App Testing Guide.
For a networking overview, please review About Networking. For a more
specific overview of App Review’s IPv6 requirements, please review the
IPv6 and App Review discussion on the Apple Developer Forum.
Please see attached screenshot for details.
Before I submit for review, I have tested it on simulators and real devices, both takes 5-10 seconds to open.
I am using Firebase and Ionic, can someone give me some suggestions, what caused this issue? I google searched that Firebase supports IPv6 and now I have no clue why the issue occurred.
There's no hardcoded IP in the source, the only URL I am using is querying rates from Canada Post by url: 'https://ct.soa-gw.canadapost.ca/rs/ship/price'
Any help is appreciated.
We are having the same kind of report from Apple despite the fact we are testing on 6 different devices, iOS 11, 12, 12.1 with or without network.
We are also getting no issues from our beta testers.
As far as I can tell, on the Launchscreen we are spending about 6 seconds (iPhoneX) waiting for Metal to launch. There is nothing else in our log until our first VC hits its viewDidLoad.
We had the same kind of report two weeks ago with a very different iteration of our app, on resubmission the app went through
Now we have tightened up a lot of app behaviour and been rejected for the same reason multiple times
Its frustrating because of the lack of supporting information from Apple, such as logs.

Fabric data different from iTunes Connect data

Our Daily New User-count from Fabric is consistently bigger than the App Units per day that we get from iTunes Connect.
Fabric defines Daily New Users as
The number of new app installations across all devices seen on a given
day.
And iTunes connect defines App Units as
The number of first-time app downloads made on the App Store using iOS
8 or tvOS 9, or later. App updates, downloads from the same Apple ID
onto other devices, and redownloads to the same device are not
counted. Family Sharing downloads are included for free apps, but not
for paid apps.
What can cause this discrepancy? I can see many reasons for how Fabric could report a lower number (such as users downloading the app but never opening it, or waiting too long to open it), but not the other way around. Our average send-usage-to-developers opt-in rate is 23%, but that does not affect the App Units number if I am not mistaken.
Is your app available on both iPhone and iPad? If so, then the fact that, as you point out, Apple doesn't count downloads from the same Apple ID onto other devices might be causing this discrepancy? You can install iPhone apps on your iPad even if it's not officially supported, so the rule might still be affecting your app. Also, if your app is a paid app, then the Family sharing rules would also affect the numbers. I've actually wondered how iTunes counts new users, so thanks for that info!
I'm not sure why the numbers are consistently bigger for you on Fabric, because for my app they alternate a bit.
I hope you might have got the answer. If not follow the link below http://help.apple.com/itc/appanalytics/#/itc7bea1545f
It seems there are users who don't opt-in app analytics data.
Apple only shows data from users who have agreed to share their
diagnostics and usage information with app developers.

If I use third party crash-analytics sdk in my production app , will it suppress my iTunes-Crash Report?

My app is now going on to production phase. If I use third party crash-analytics sdk in my production app , will it suppress my iTunes-Crash Report.
No, it won't. I have Fabric with Crashlytics installed in various apps and I still see the reports in iTunes Connect.
Apple will always get crash reports. Apples crash reporter runs out-of-process, all 3rd party crash reporting solutions run inside your apps process. Depending on the quality of the 3rd party crash reporter implementation, Apples crash reports may not have the best quality.
There are some crash reports that you will only get from iTunes Connect which is basically all that are technically app kills and not crashes, e.g. when your app blocks the main thread too long, or if it takes too long to launch or exit the app.
One difference is that you may not get access to every single crash report from Apple and it is unknown when they show reports and if they do any sampling or similar. Crash reports will also only be sent to Apple, if the user agrees to share this information in general when setting up the device or changing the according setting in the settings app. There are reports that only about about 30% of device users activate this settings. The amount may vary by app and can of course also yield in bigger percentages.

Users say that the iOS app crashes without any further explanation

I have an app in iTuens which is quite popular and the user are writing bad reviews saying that the app crashed sometimes without any reason or explanation.
I have tested the app both on simulator and on a real device. It works fine for me and there are no memory leaks in xCode either.
What can I do in this situation to fix the crash?
Is there any crash reporting API that I could implement in the app so that the user can send the crash log to me within the app?
There are multiple options available, some fully open source, some partly, some free, some paid.
iTunes Connect mostly doesn't work. The reasons are:
In older iOS Versions, people needed to sync the device to iTunes, which would then upload the crash reports to iTunes Connect. But these users had to agree to "sending anonymous usage and diagnostic data" to Apple when setting up the device. Most people just don't allow that.
In newer iOS Versions (I think it started in iOS 6) the device is sending crash reports directly to iTunes Connect. BUT also in this case, the user has to approve "sending anonymous usage and diagnostic data" when setting up the device. Most people just don't allow that again. You can check yourself if you allowed it in the Settings app under General, About, then scroll down to Diagnostics & Usage.
So the best way to get crash reports (sadly) is to include a crash reporting library into your app. Due to privacy reasons, you should allow the users to allow or deny sending the reports. Most people do allow this, since the dialogs mostly say something like anonymous data to fix the bug that caused the app to crash and (hopefully) won't send any privacy problematic data in then too. But the magic is I think, that it doesn't say usage data in such a global context. Never had problems in all the years not getting crash reports even though showing alerts and letting the users decide, also with an option to Always send.
The following answer shows an overview of available crash reporting solutions: how to generate crash report using code like crash report provided by Apple
Just an update for ios 8 & 9:
On your iOS device, go to Settings > Privacy > Diagnostics & Usage, and select Automatically Send or Don't Send.
When you turn on Automatically Send, you can also turn on Share With App Developers. This helps developers improve their apps by allowing Apple to share data, as well as statistics about how you use their apps.

How to get the Crash Log from Apple?

We developed an app, and it works perfectly on several different emulators and devices, not once crashed, but both times we tried submitting to Apple it gets back to us as "2.1 - apps that crash are rejected" (or something).
I cant seem to find the log from them, or any additional infos. Is the crash log available anywhere? Or just ANY info? They only say that it crashed on an iPad 3rd Gen with iOS 6. We ran on a device like that and it didnt crash for us.
Unfortunately, Apple doesn't provide detailed logs of their review process, although crash logs are sometimes provided, as indicated by #jsd in the comments below.
In theory, crash reports get synchronized with iTunes and can be collected by Apple and provided to you via iTunes Connect, but in practice, that rarely works - or only with large delays.
However, you could integrate some Crash Reporting into your App. Here are a few services that allow you to do that without much hassle:
HockeyApp
Crittercism
BugSense
TestFlight
Crash reporting integration in production versions of my apps have been proven to be very helpful, so I'd highly recommend this. Good crash reporting services provide an SDK to be included in your app, and generate symbolicated, readable, ready-to-use crash reports that make tracking bugs very easy.
As for the cause of your app's crash, here are some basic guesses:
Do you use ARC (Automatic Reference Counting)? You should.
Did you run the Static Analyzer in Xcode (Product ➞ Analyze)?
Did you test with different environments (e.g. internet connection via 3G, WiFi or none at all)?
Have you deleted and reinstalled the app on your device, or did you just update it?

Resources