0

In my app, I go to a webpage which is a keynote file. Users can browse that keynote and follow along on their own device. I allow all rotations, and it rotates fine. To make more room when in landscape, I have it hide the navigation bar on swipe. When I do this in portrait, it hides it and all is fine. When I do it in landscape, I get a crash. All I get in console is Message from debugger: Terminated due to memory issue. The code is:

- (void) viewDidAppear:(BOOL)animated {
    self.navigationController.hidesBarsOnSwipe = YES;
}
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

}

- (void)viewDidUnload {
    [super viewDidUnload];

}
-(void)viewWillAppear:(BOOL)animated {
    [super viewDidLoad];
    self.title = @"Worship Slides";
    [worship loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/Fritch/worship.key"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];

}
user717452
  • 33
  • 14
  • 73
  • 149
  • Run your app through Instruments and find out where all the memory is being used, then try and reduce it. – Ashley Mills Jan 31 '17 at 17:00
  • I've never used Instruments so not sure how to do that. It only crashes on actual device, simulator has no issues. – user717452 Jan 31 '17 at 17:34
  • You've got limited memory on device - on the simulator you don't – Ashley Mills Jan 31 '17 at 17:35
  • This sounds like a great opportunity to learn how to use instruments. **Cmd-I** to build and run in Instruments, pick Leaks or Allocations and look where the memory is used – Ashley Mills Jan 31 '17 at 17:36
  • @AshleyMills Ok, so at startup, I have some leaks, but nothing is larger than a few kb, and there are no new leaks along the way leading to the crash. At the moment the app crashes, there is nothing new in Allocations or Leaks to explain the sudden use of memory – user717452 Jan 31 '17 at 17:42
  • That looks like UIWebView which is ancient (iOS 2) and super crashy. I am not sure if WKWebView supports keynote, but you should try it and see because my experience is that its much more stable and switching from UIWebView to WKWebView will dramatically improve the stability of your app. – Josh Homann Jan 31 '17 at 17:55
  • @JoshHomann Ok switching to WKWebView fixed the issue, however, the WebView extends beyond the side of the screen. `_theWorship.frame = CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);` – user717452 Jan 31 '17 at 18:05
  • That only works if its in viewDidLayoutSubviews and even then its a bad idea; you should be using auto layout instead: http://stackoverflow.com/questions/26180822/swift-adding-constraints-programmatically/40184218#40184218 – Josh Homann Jan 31 '17 at 18:15
  • @JoshHomann I made a new question related to this http://stackoverflow.com/questions/41964845/wkwebview-constraints-dont-work if you want to check it there. – user717452 Jan 31 '17 at 18:26

2 Answers2

2

You should not be calling [super viewDidLoad] from the viewWillAppear handler. This could be contributing to your problem, since viewDidLoad is for one-time-init stuff.

Chris Edgington
  • 1,208
  • 12
  • 11
0

I'm guessing this is old code you've found somewhere. Not that this will solve your problems but…

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear: animated];  // Add super call
    self.navigationController.hidesBarsOnSwipe = YES;
}

// No need for this method if you're not actually overriding it
//- (void)didReceiveMemoryWarning {
//    // Releases the view if it doesn't have a superview.
//    [super didReceiveMemoryWarning];
//
//}

// viewDidUnload was deprecated in iOS 6
//- (void)viewDidUnload {
//    [super viewDidUnload];
//
//}
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated]; // User correct super call here
    self.title = @"Worship Slides";
    [worship loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.316apps.com/Fritch/worship.key"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0]];

}
Ashley Mills
  • 50,474
  • 16
  • 129
  • 160