My app heavily relies on the three20 TTTableViewController. I am currently working on error handling, specifically related to connectivity issues. I have found that if I load with createModel that it displays a nice error msg about the status of connectivity. However, when I do a drag to refresh... it does not show me the error screen when there is no connection. Besides creating a separate datasource and model (local) and doing createModel again, is there a better solution to this issue?
you can cache the results for how long you want to by modifying the cache settings in your model's load function, as such:
request.cachePolicy = TTURLRequestCachePolicyDefault;
request.cacheExpirationAge = 3600 * 60;
Related
I recently updated to Xcode 7 and upgraded my iPhone to iOS 9. I have developed and released an iOS app that had worked perfectly fine on the latest version of iOS 8 and Xcode 6.
Upon trying to go through the process of updated the app for iOS 9 support, I am getting the most ridiculously strange error that has left me baffled.
I have done all the syntax corrections automatically through Xcode, and now my app builds properly. It even runs fine at first.
I have a button that segues to a view controller with a WebView. This view controller loads a link that will display either an image, website, or video from youtube. The content is loaded perfectly fine as always. However, the program will crash and reboot the simulator (and my iPhone) and send me to the lock screen when I click the Back button (I am on a navigation stack).
In Xcode, I get the following messages:
XPC Connection Interrupted.
Terminating since there is no system app.
I have Flurry analytics integrated in my app by the way, not sure if thats an issue.
How can I fix this issue? My searches for XPC connections do not seem to return problems similar to mine. I do not even have a clue what an XPC connection is, so why is this in my app anyway?
EDIT: I have found a workaround for the issue. I cannot really say it is a fix.
The crashing was occurring during the use of the method self.navigationController?.popViewControllerAnimated, when set to true. I happened to set this to false, and the crashing stops (now the transition looks awful).
I do not know why this works, and just adds to my confusion.
The problem lied in the storyboard for me as well. I created a new project and laid out the views and everything seemed to be working fine. I found these couple lines in the storyboard source (right click on storyboard and select view as -> source code) which weren't common between the working version and the broken version:
<keyCommands>
<keyCommand/>
</keyCommands>
I have no idea what those lines are supposed to do, or how they crept into my storyboard file, but they were what was crashing the app so hard that the phone had to restart. I removed those lines from my main project and everything worked again.
This error can be caused by executing a loop repeatedly. In my case it was a 'for' loop in which I reset the counting variable. As soon as I added an NSLog in the loop it was obvious.
I just faced the same problem. I don't know if that will help you, but I also think it's coming from the Storyboard:
In my case, the problem is coming from a UITextView. Whenever I try to change the default text inside it, I have this error. If I let the default text or leave it empty, the app works fine. Making an IBOutlet and changing the text programmatically works as well.
I tried with other UI elements, but only the UITextView seems to have this issue.
I have struggled with exact same error. Through a process of elimination I established that it had nothing to do with the any class but had to do with the storyboard. Luckily I keep regular backup copies and I tried to compare storyboards to establish what I had done - but could find nothing obvious.
The backup copy worked fine and I was able to copy my controller classes (from the faulty copy with the changes) into the backup copy and they worked fine.
I think there is a bug possibly in storyboards.
I have same error message when I place a subview in -layoutSubviews method:
-(void)layoutSubviews
{
[super layoutSubviews];
[self populateByImageViews];
}
It causes infinite cycle of layout process and crashes app. Don't place subviews in this place!
Deleting UITextView from the one of the view in Storybord removes the error in my case.
In valueChanged: method of a UIControl, I had the same problem
so I made the code inside valueChanged: to run in main thread and it solved the problem.
#IBAction func valueChanged(sender: AnyObject) {
dispatch_async(dispatch_get_main_queue(), {
//code
}
}
For me was some missing constraints with a UISearchBar, but the error was only in the simulator.
I only add some constraints and works better
For me it was xcode live issues caused by IB_DESIGNABLE
If you have any IB_DESIGNABLE in source files, the system's live tracker will check for issues in StoryBoard too. It may leads to unnecessary building.
To disable it-
Open Storyboard file. Editor -> Automatically Refresh Views (Uncheck)
If you needs to Disable Live issue tracking
XCode -> Preferences -> General -> Issues -> Uncheck Live Issues
Reference
My issue probably originated with some storyboard issue, but I cleaned the project, restarted Xcode AND restarted the simulator app and that fixed it.
When using QLPreviewController, I am confronted with this problem. Error messages as follows,
XPC connection interrupted
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)
Since XPC means OS X interprocess communication, so I think this can solve the problem, especial when updating the UI
dispatch_async(dispatch_get_main_queue(), ^{
// do what you want to do.
});
For Swift 4+, user
DispatchQueue.main.async {
//Your Code
}
I'm displaying a list of icons downloaded from the web with text in a table view. The icons can be changed on server side and I need to replace them as soon as new icons are getting available. I try using the following code:
[imgView setImageWithURL:url placeholderImage:[UIImage imageNamed:#"table_avatar_icon"] options:SDWebImageCacheMemoryOnly];
And call [[SDImageCache sharedImageCache] clearMemory]; In my refresh callback, but it does not purge the contents of the cache. More to it, even if I close the application and open it again the image is still there.
I found only one way to clear the cache and it is by calling [[SDImageCache sharedImageCache] clearDisk];. Which only works after I close and reopen the app.
How can I force SDWebImage to not to use disk caching?
SDImageCache *imageCache = [SDImageCache sharedImageCache];
[imageCache clearMemory];
[imageCache clearDisk];
Don't forget to put these lines of code in your didReceiveMemoryWarning, too.
Located the source if an issue. It seems that I was deceived by the Singleton pattern used in SDImageCache. The cache for extension that is used over UIImageView is being controlled by SDWebImageManager which has an instance variable of SDImageCache. If you want to clear the cache for extension you have to call its imageCache's methods like clearDisk and clearMemory.
Only following code worked for me : Swift 5.0, Xcode 11, iOS 13, SDWebImage pod 5.0
SDWebImageManager.shared.imageCache.clear(with: .all) {
print("deleted all")
}
where you choose options like SDImageCacheType.disk, SDImageCacheType.memory, SDImageCacheType.disk
Also if you want to remove specific image from cache use following:
SDWebImageManager.shared.imageCache.removeImage(forKey: "url of image", cacheType: .all)
Except SDImageCache methods, I strongly advise you to check your image urls. In my situation I tried every method for imageCache and memory issue was still continue. Crashes were occur mainly on iPhone 4s because of hardware it couldn't handle it.
Main issue was url ampersand encoding!
In example, check out these urls: first url is using "&" and second one is not. Because of ampersand my JSON library can't read the width and width value get much higher then it should be. That is why I had a memory issue.
1) /select.php?imageid=101961221 "&" ;width=100 "&" ;isWatermarked=true
2) /select.phpimageid=101961221&width=100&isWatermarked=true
Also the latest versions of SDWebImage library has include UIImageView+WebCache.h class and it really nicely handle cache problems.
The icons can be changed on server side,
so you need to load with refresh cached every time.
if you're using latest SDWebImage framework (5.12.x)
you can call it like this,
[imgView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:#"xxx" options:SDWebImageRefreshCached];
edit at 220112.
I'm currently using TTThumbsViewController in my project. I'm getting all the urls for TTPhotoVersionLarge and TTPhotoVersionThumbnail from the web so I can't tell that a url for the thumb images will work or not.
Currently the TTThumbsViewController will just display an empty image if the thumb url can't be loaded.
So I want to be notified if a thumb fails to load and do extra error handling when that happens like:
Try to load the url for TTPhotoVersionLarge
If that fails again display an error image (which is included in the bundle)
I have looked into the three20 code but can't find a proper place where I can implement this proper error handling.
The Three20 library is great, but I've found that it's often hard to change parts of their library such as this. For instance, TTThumbsViewController basically only allows you to set the dataSource and then takes care of the rest. If you want more control, perhaps look into code such as AQGridView: http://quatermain.tumblr.com/post/528737778/aqgridview-lives-for-my-ipad-dev-camp-hackathon
I've chosen to use that over Three20's equivalent because it gives you more control over what happens with your data.
Edit: In response to using TTThumbsViewController heavily, you may want to look at this method in TTTHumbsViewController.m:
- (NSString*)URLForPhoto:(id<TTPhoto>)photo {
if ([photo respondsToSelector:#selector(URLValueWithName:)]) {
return [photo URLValueWithName:#"TTPhotoViewController"];
} else {
return nil;
}
}
It looks like you should be able to specify a different value there so long as you can find something to add to the if statement determining if the initial loading failed from the dataSource.
how can i debug applications for iPhone in Objective-C, XCode
i mean ok, XCode and debug mode is fine, but when my application crashes on
BAD_ACCES (or smth. smilliar) i just get the trace to assembly
when iam debugging C++ and lets say want to access an invalid pointer, i get a trace right to the line of code where everything crashed... here i just get a trace to many internal functions in assembly, so i dont have a clue what and where went wrong
probably some release / retain problem, but how can i find out?
thank you
Here we go with the full answer:
I've had a look at your app and I think there is a problem with the combination of the UINavigationController and asynchronous http loading in two places. Enabling the zombies did reveal those two errer. The first on I was able to reproduce, the seconds one popped up several times and then not any more.
*** -[DetailViewController respondsToSelector:]: message sent to deallocated instance 0x56d6030
*** -[SearchViewController respondsToSelector:]: message sent to deallocated instance 0x56daa10
I've just throttled my bandwidth to see if those errors are connected to http requests. Look at [Throttling Bandwidth On A Mac][1] to set up a slow connection. I set it to 5KBytes/sec.
The first error occurs if you go very quickyl down to the details and then two levels up again and as a last action to trigger the error: click on search. The stacktrace shows a
#2 0x004545b8 in -[UIWebView webView:decidePolicyForMIMEType:request:frame:decisionListener:]
and there are some threads open, so looking at the dropdown, there is a webThread. Showing that thread reveals something going on with the webview loading the detailPages url. This hints that the webiew actually finished loading in a seperate thread and wasn't able to connect back to the webview itself [DetailViewController respondsToSelector:]. This can be easily proofed: remove the loading of the request for the webview: I wasn't able to reproduce the error.
Solution problem 1
The problem is easily fixed, as the webview is not released in the dealloc. Setting delegates to nil of objects is also recommended, but not needed in this case.
- (void)dealloc {
webView.delegate = nil;
[webView release];
}
The second error
The stackTrace shows a
CLLocationManager onClientEventLocation:
Solution error
Same as error 1, set the delegate to nil and release the locationManager.
When your app crashes you cann open up the debugger in the left hand window you can see the stacktrace. You can double click any line which will jump to correct position in your code(if the called method is of yours).
Goto Project->Edit Active Executable->Arguments Tab
Add the Variable in the lower window by clicking on +
Name:NSZombieEnabled
Value:YES
This tries to resolve memory addresses to class names for bad excess errors.
To find out about memory leaks, open Run->Run with performance tool->Leaks. This will open up instruments which is a brillant tool to find leaks.
Are you using XCode 3? If so, I would highly advise upgrading to XCode 4. The debugger in XCode 4 is brilliant in comparison. It let's you step back through the code and see exactly what caused the crash.
I have created an application which consists of a screen with a play button to play an audio file. The problem occurs after running the application for 10 minutes; it throws this message in the console:
ImageIO: CGImageRead_mapData 'open'
failed
'/Users/indianic/Library/Application
Support/iPhone
Simulator/4.2/Applications/A511E515-6FEA-4D0D-A5C5-95740B14C858/VisualMath.app/pi_play.png'
error = 24 (Too many open files)
After these message the application crashes. Anyone knows why this problem occurs and how to fix it?
Thanks in advance.
As I have work with database in the same application there is some point where i need to fire sql query twice. because I have fire query twice the database file is not getting close and because of that the file open many time in my application. and because of that the application is crash with giving this error.
so always check for the database file is getting close or not for this kind of the error.
I had a very similar problem. For me it had to do with the number of iterations (count) rather than time running, and I just tracked the problem down to my use of the stop method. It appears that the stop method leaves some resources in memory that release does not (I'm guessing for a possible resume). And even if you call release after stop, which is what I was doing in audioPlayerDidFinishPlaying:successfully: , it's wasn't enough if i'd used stop beforehand. But replacing stop with just release and nothing else made my problem go away.
It looks like you keep loading images for the play button which causes the exception. If this is the case, try loading them once and change the icon of the button when needed.
If you are using NSFileHandle close the file when you are done with it, or use [UIImage imageNamed:(NSString *)];