App started running slow without any changes on code - ios

So, yesterday my app was running fine, but today it started to run really slow for no reason.
I've been trying to find the cause using CACurrentMediaTime() and now I know that its between didFinishLaunchingWithOptions on AppDelegate and my viewDidLoad of my first ViewController.
From here on it always takes about 10 seconds to load any new View, but inside the view it runs fluid.
I can post my logs here:
app[311:25582] 4665.159450
app[311:25582] Splash - 4673.318206
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(#"%#",[paths objectAtIndex:0]);
NSLog(#"%f", CACurrentMediaTime());
return YES;
}

I've solved the problem by deleting the ViewController and creating a new one.
What I did to find the possible cause of the problem:
Went to an older version of the app to see it running (it was running ok)
Copied the Storyboard to the old project (started to run slow again)
Copied only the ViewController (again, it was running slow)
Copied only view by view (it worked!!)
My guess is that the ViewController was with some error and was messing up the rest of the app.
Just posting here the answer so that I can help someone else.

Related

Document folder for previously working app using Document Browser disappeared

I have an app built that uses the UIDocumentBrowser. It was working fine until I tried to add an ImagePickerController to allow the app to use the camera and take photos. The Documents folder is now no where to be found on the "Files" app or in the app I am developing. I could find it in the Finder on the Mac I am using for developing the app.
I tried deleting the entire app and data and installing a cleaned build.
I have this sitting at the top of the app launch method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_datapath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
if (![NSFileManager.defaultManager fileExistsAtPath:_datapath])
[NSFileManager.defaultManager createDirectoryAtPath:_datapath withIntermediateDirectories:YES attributes:nil error:nil];
When I run it in debug, it finds the already created documents folder so skips over the createDirectoryAtPath method.
Any ideas what's happening and/or how I can fix it?
Note: I never got to the point in the app where I could test the ImagePicker before this problem happened and removing the code I added didn't fix the problem.
Must have been cached information. Powered down the iPad and restarted fixed the problem.

NSUserDefaults objectForKey sometimes nil

I've just noticed that a key that exists in my **NSUserDefaults**
is returning nil quite often. It seems about half the time it's
correct and the other half it's not. I say half the time, but I dont
mean that its flip-flopping, its just 40-50% I see it not work.
When I write the initial value, I call synchronize immediately.
I use this key as the applications
revision I set when a new user signs up.
The following code returns nil:
#define kDBrevision #"revision"
NSString *rev = [[NSUserDefaults standardUserDefaults] objectForKey:kDBrevision];
When I launch the app and just monitor the value (without
writing any NSUserDefaults), the value sometimes is valid
with no modifications to the NSUserDefaults at all.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *r = [[NSUserDefaults standardUserDefaults] objectForKey:kDBrevision];
NSLog(#"revision %#", r);
_exit(1);
I have no idea why this is happening. Im running iOS 10 on my
device connected to Xcode 8.2.1. Anyone have any ideas?
Thanks
EDIT:
I started talking to apple about fixing this and found out that if you have
file protection complete turned on, it can be the cause of this issue
showing up from time to time, however apple told me that my particular
case (which is the only one I was sure of at this time) is a bug.
The case is when you use Xcode to launch the app on the device it should
not fail like this and it occasionally does. No idea when or if it will
be fixed. Instead I moved my critical strings from the defaults to
the keychain instead.
This appears to be an Xcode 8 and/or iOS 10 bug. I ran into it myself and conclusively narrowed the case to UserDefaults intermittently returning nil when in fact there was data for the key. Specifically, I set the data once, then removed the set logic and executed only the get logic, repeatedly, and sometimes got values, sometimes got nil.
I changed my Run scheme to use Release configuration and ran the app on device without the debugger attached and the issue disappeared, that is, the get logic produced the correct value every time I executed it (~30 times).
Here is some more discussion:
iOS 10 with XCode 8 GM caused NSUserDefaults to intermittently not work
iOS 10, NSUserDefaults Does Not Work
https://forums.developer.apple.com/thread/48700
https://forums.developer.apple.com/message/143155#143155
try below code in didFinishLaunchingWithOptions
Swift 3.0
UserDefaults.standard.synchronize()
Obective - C
[[NSUserDefaults standardUserDefaults] synchronize];

Meteor Cordova startup time is ridiculously slow?

As you can see in the gif, the startup time of the localmarket ios meteor app is ridiculously long. It took around 7 seconds normally, however once i added fastrender and fastclick, it dropped down to 4 seconds. Why is this? I noticed the Verso app loads far faster. How can I make a meteor ios app that loads faster? 4 seconds absolutely kills users, and this happens everytime the app is restarted. Any fix to this?
Btw, appcache breaks this application.
LocalMarket
Solved it myself. The problem is the launch-screen package.
meteor remove mobile-experience
meteor add fastclick
meteor add mobile-status-bar
meteor add meteorhacks:fast-render
Worked like a charm for me. Heres an article I wrote on this topic: https://medium.com/#gautham.gg/reduce-the-launch-time-of-a-meteor-mobile-app-e2f009951011#.8uovmstb5
Change your splash screen time from AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[NSThread sleepForTimeInterval:5.0]; //5 is the time in second for splash screen
.
.
.
}
Add this within your layout onRendered
if (Meteor.isCordova) {
navigator.splashscreen.hide();
}

PLCrashReporter doesnt open when the app crashes

first time user of PLCrashReporter. I have written the code in my appDelegate.m file
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
NSLog(#"inside applicationdidfinishlaunching to do crash reporting");
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
NSError *error;
if ([crashReporter hasPendingCrashReport])
[self handleCrashReport];
if (![crashReporter enableCrashReporterAndReturnError:&error])
NSLog(#"Warning: Could not enable crash reporter %#",error);
}
I wrote handleCrashReport as it is in the example. I also on purpose crashed my app on clicking a button.(NSRangeException index 0 beyond bounds for empty array) like this:
NSMutableArray *mtestArray = [NSMutableArray new];
NSLog(#"%#",[mtestArray objectAtIndex:0]);
It throws exception (i.e. goes to main.m file. Doesn't go to home screen. It stays on the main.m file). I stop the execution and restart the app and it goes to a screen (this screen occurs if it were correct actually). I dont see a pop up saying send crash report or don't. I added CrashReporter.framework and libcrashreporter-iphonesimulator.a to my project. I changed mach-o and perfom single...as told in the article. I have been at this for more than 2 hours. Why dont i see the error dialog?
I put breakpoints at my applicationdidfinishlaunching and they NEVER get hit. I deleted my app and reinstalled (re-run) and still no go. Also my project is an iPad project with iOS 6.1. I read that crash report dialog appears on second time start of the app. But it won't any time,2nd or 3rd. If you need more information, please ask. Thanks
EDIT : Does plcrash reporter work for iPads also? I took the help from this blogpost
http://mandeepdhiman.blogspot.com/2011/10/crash-reporter-for-ios.html

Auto redeploy on iOS Simulator XCode

Is there any way to [edit] have a fresh [/edit] redeploy your app from xcode onto the iOS simulator when you hit run, without have to delete [edit] the existing data from the app [/edit] every time?
If you want it to start with empty data each time, you can use the Xcode organizer to take an application data snapshot of a freshly started app, add the snapshot to your project and then edit your scheme and go to Run -> Options and select the snapshot in from the Application Data popup menu. That way when the app is started, it always starts with the same, presumably empty, data.
I don't think it clears NSUserDefaults, though.
You shouldn't have to delete it every timeā€¦ you should just be able to hit run and it will overwrite or otherwise update the version that is loaded there.
I normally have a debug button to remove all data and add in fake data if necessary and wrap them in a DEBUG flag. This allows me to control it without having to restart the app.
- (void)viewDidLoad
{
#if DEBUG
// Make Button and hook it to clearAllData
#endif
}
- (void)clearAllData
{
// Clear the Core Data databases
SDAppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
[myDelegate clearAllData];
// Clear the UserDefaults
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]];
// Run the initial Setup again
[self setup];
}

Resources