is NSLog() stored on the device (iPhone etc)? If so, where? - iphone

Should all NSLog() calls be deleted in the final app for iTunes?
In my iOS app, I've got lots of NSLog() for debug.
Should I conditionally code them out before uploading to iTunes?
This is for an app for: iPhone, iPod, iPad
Thanks.

I'll answer the OP's question in the title about where the logs are stored on the device. NSLog() uses the ASL (Apple System Logger). Programmatically, you can only read the last 256 entries (which is what Xcode shows in the Organizer, for example).
However, if you want to access the full files, they are stored in:
/private/var/log/DiagnosticMessages
When you look into that directory (note: device must be Jailbroken), you'll find a long list of *.asl files.
I found a tool to parse those files, but I haven't tried it yet, so YMMV:
Parsing Apple System Log (ASL) files on iOS and OSX for Fun and Evidence (and a Python script to do it for you)

You don't have to remove all of them; in fact, they can be useful if your app crashes on a user's phone and you want them to send you a crash log. When a user syncs his/her phone, the crash log is located in the folder
~/Library/Logs/CrashReporter/MobileDevice/<DEVICE_NAME>
If you have NSLog()s you may gain useful information just as you would when debugging. As the others pointed out, don't overdo it, but it they could end up being useful.

Yes, We should remove all the NSLog() calls before uploading to iTunes. That is done mainly for better performance.
Even if u dont remove them, no problem. It will be approved. But if u have lot NSLog() s, the that will def. affect the performance.

Try using this for your NSLogs:
#define DEBUG
#ifdef DEBUG
NSLog(#"Your tests outputs");
#endif

Not all. You should keep the error logs. That will make it easy to locate if there is any error or crash.
Its possible to see NSLog messages using Organizer too.

You dont need to remove NSLogs if they added against DEBUG mode. So even if your app crashes and if it contains user personal data, it will be removed by ios. So do not worry about user data and NSLog. Refer https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/AnalyzingCrashReports/AnalyzingCrashReports.html
Still if you want you can use this PJiOSAppConsole in your application. It will keep logs in your application only. You can use it at runtime by adding snippet in #ifdef then remove whenever you want to go to live. Easy to integrate and use.

Related

healthStore.requestAuthorization() crashes Apple watch application

I'm trying to collect health data in my Apple Watch application but when I call healthStore.requestAuthorization my app always crashes. I have set NSHealthShareUsageDescription and NSHealthUpdateUsageDescription in Info.plist as required but it still crashes.
I started a new project and am just trying to request authorisation, there is no other functionality that could affect it.
Any ideas why this is?
Thanks for any help.
I found what the issue was. There are two Info.plist files that need NSHealthShareUsageDescription and NSHealthUpdateUsageDescription. One in the project file and one in the watch extension file. I had only done one of these.
The strings for these also need to be a reasonable length and cannot be just a couple of words.

Recognise an out of memory crash (IOS)

Our apps are live on the app store.
I wish to recognise crashes of out of memory that some users are getting.
I understand there is no way to 100% recognise an out of memory crash.
Is there any way to recognise these crashes(with a pretty large probability) by doing some logic in the applicationDidReceiveMemoryWarning? (I am not talking about finding it in xcode during development time, i am talking about code that will recognise the out of memory crash from actual users and will log something to file)
While I was looking for any service or library that give me OOM tracking, I could only find this article from Facebook engineering:
https://code.facebook.com/posts/1146930688654547/reducing-fooms-in-the-facebook-ios-app/
The idea is to deduce the reason why the app needs to be launch, checking different aspects (like if the app was at background, if there is an app/OS update,...).
Discarding all the other possible reason that can force the previous app exit, you can know if the reason is a background out of memory or a foreground out of memory.
It would be nice to have a library that implements the Facebook article procedure. But nowadays I couldn't find any, probably there is some reason that make this difficult or may be impossible to add it as an sdk.
If anyone knows any service, please share it with everyone with a comment or a new answer.
Edit:
I have discovered this github (https://github.com/jflinter/JRFMemoryNoodler) with an implementation of the Facebook post procedure. I haven't tried yet, but we will deploy it in our apps to try it.
Look out for the applicationWillTerminate message in your app delegate. This is called if you app is terminated by the system (due to e.g. low memory), but not if the user leaves the app in the usual way by pressing the home key. Note: if your app is in the background and memory runs out, your app gets killed without any messages being sent to it.
YMMV, especially with older versions of iOS, and it's worth researching to ensure that the above is accurate.
The images at this blog post are quite informative (although slightly dated).
For more info, see How to know whether app is terminated by user or iOS (after 10min background)
Firstly Analyse your application by clicking on the Product at the top menu bar of your Xcode and click on Analyse section it will show you the number of leaks on in the application and can take you to the place where leaks occurred. This is how you can find the memory leak and rectify it.
Secondly it above does not worked then see to the view controller where crash occurred and check whether you have left any object to release.
Hope this might help you to resolve your problem.

ALAssetsLibrary ALAssetsLibraryDataUnavailableError

I'm trying to make sure to cover all my bases with regard to ALAssetsLibrary failing for whatever reason. In looking through the possible errors that could occur when calling:
- (void)enumerateGroupsWithTypes:usingBlock:failureBlock;
i noticed that ALAssetsLibraryDataUnavailableError, but there isn't much information about what might cause this. I want to show an error screen accordingly.
Any insight would be appreciated. Thanks!
I encountered the ALAssetsLibraryDataUnavailableError in 3 cases:
When using the simulator and switching between iPhone and iPad simulator.
On the device, when the photo library was corrupt or in an inconsistent state.
After performing an iOS upgrade without having synced to iTunes.
I would recommend to display a message to the user, you run into this error, recommending:
1. To open the photos app...this usually fixes an inconsistent library.
2. If that doesn't help to reboot the Device and sync with iTunes one time.
Cheers,
Hendrik
Ok I found out another peculiar circumstance where this error appears:
Trying to save an UIImage to photo roll/photo album using UIImageWriteToSavedPhotosAlbum.
iOS asks the user for permission to access the photo library - the user denies(!)
In the completionSelector, the supplied NSError then contains ALAssetsLibrary ALAssetsLibraryDataUnavailableError.
You would think that the error would be something else like ALAssetsLibraryAccessUserDeniedError or ALAssetsLibraryAccessGloballyDeniedError. But it's not. It's just ALAssetsLibraryDataUnavailableError.
This was tested on iPhone 5, iOS 6.0.1. Maybe it's not an error, or it is and they will fix it someday.
Anyway, the "fix" is to have the user go into Settings→Privacy→Photos→have your app turned on here. The localized fix suggestion message is WRONG - it suggest to open the Photos app. No other information about the error given. Anyway, the user should probably know that he/she pushed the "Deny" button - still they might have done so by mistake and later they would have no idea what is going on.

output different from simulator and iphone device

The output from simulator and iphone device is different. what is the actualy problem?can download the sample code from below link. the path of the road is not the same for both. i also need to move the car from start to end with the validation. currently my validation is not working.all the details are in Readme
Link Download (1.3MB)
There are a lot of situations where the behavior of the simulator and the device differs. Mostly they are triggered by bugs in your code, like messing up your memory management or trying to write to a file that isn't writable on the device.

reading a file saved by another app in iphone

Is there a way to have an app write a into a file and then have another app read from that file?
I mean writting into the file system of the iPhone.
I want to do this without using an internet connection. So uploading the file and then downloading from the other app is not what i mean.
Thanks!
It appears that there are ways you can, but it won't get approved by Apple if you do.
See http://blogs.oreilly.com/iphone/2008/09/sandbox-think-like-apple.html for more information.
The current sand boxing of applications does not allow this, however it appears that this may be available in future iPhone OS versions. Reference
I'm not sure exactly what circumstances you're in here, but you could register app B as a handler for a particular protocol, and have app A try to open such a link (e.g. appB://yourinfohere). It depends on how much data you want to transfer and many other things, but it might work.