I know this question has been asked several times, but Im looking for a more general answer.
I have developed an app for iOS 6, I tested it on simulator(Retina 3.5 and 4 inch) and also on an iPhone 4 device.
It has never crashed but when I submitted the app to Apple and they answered with:
We found that your app crashed upon launch on iPhone 5 running iOS 6.1.3,
Looking at the crash log
We see that it crashes in line 164 from a index out of bounds, which makes sense because I have this code there:
I added that "if" to stop the execution whenever the indexTimesArray was bigger than the length of the array and see why that happened, but I was unable to reproduce the error. I never get an index out of bounds as they do...
It's true that I haven't test it on a iPhone 5 device, but I have XCode 4.6 and iOS 6.1 on my computer, and also a iPhone 4 with iOS 6.1.3, but it's also true that the guys at Apple are getting the app crashed, so how to reproduce the error?
I tried to install the app from TestFlight because it installs it as a brand new app, just like they do when they test it, but still no errors...
How can I reproduce the error? Could it be a problem with th build settings?
Thanks
[EDIT]
I initialize the contents of timesArray in the init method of the object, like this:
- (id)init{
self = [super init];
df = [[NSDateFormatter alloc] init];
[df setDateFormat:#"yyyy-MM-dd HH:mm"];
rangeDates = [[NSArray alloc]initWithObjects:#"2013-04-11 10:00", #"2013-04-12 10:00", #"2013-04-13 10:00", #"2013-04-14 10:00", nil];
timesArray = [[NSArray alloc]initWithArray:[NSArray arrayWithObjects:#"10:00", #"11:00", #"12:00", #"13:00", #"14:00", #"15:00", #"16:00", #"17:00", #"18:00", #"19:00", #"20:00", #"21:00", #"22:00", nil]];
colorDictio = [[NSDictionary alloc]initWithObjects:[NSArray arrayWithObjects:[UIColor colorWithRed:0.74 green:0.66 blue:0.37 alpha:1.0], [UIColor colorWithRed:0.64 green:0.15 blue:0.11 alpha:1.0], [UIColor colorWithRed:0.313 green:0.65 blue:0.69 alpha:1.0], [UIColor colorWithRed:0.79 green:0.4 blue:0.59 alpha:1.0], [UIColor colorWithRed:0.45 green:0.55 blue:0.53 alpha:1.0], [UIColor colorWithRed:0.14 green:0.27 blue:0.66 alpha:1.0], nil] forKeys:[NSArray arrayWithObjects:#"showers area", #"zinctalks", #"zincnetwork", #"zincshows", #"zinclabs", #"zinczone", nil] ];
return self;
}
To figure out how to reproduce that error you have to look at the code where you create timesArray.
The out of bounds error happens because [timesArray count] is less than 2 (or the whole array is nil). So you have to figure out which condition leads to an array with one or zero objects. Maybe it happens because there is no internet connection.
It's always a good idea to wrap objectAtIndex: in a check for the actual size of the array.
I would replace else { with else if ([timesArray count] >= 2) { and add an additional else that handles <2 arrays.
First of all this is not a OS related error. Your app is crashing because the wrong index of array is being accessed.
How can I reproduce the error? : Try to use the same credential which you must have provided to apple.
Could it be a problem with th build settings? : No.
To debug the error what you can do is try to print the value of indexTimesArray before the if. Also, try to print all the values you are passing to access the array element. Which will help you track the wrong index which is being sent.
Thanks to #mayur, his comment is the right answer, "I had faced a similar error earlier with arrays in Objective-C... My suggestion would be to use self with NSMutableArrays or NSArrays"
Related
I have some trouble with the new Core Spotlight API in iOS 9. The problem is that the init methods for CSSearchableItemAttributeSet returns nil. Here is an example that does not work for me:
CSSearchableItemAttributeSet* attributeSet = [[CSSearchableItemAttributeSet alloc] initWithItemContentType:(NSString *)kUTTypeImage];
attributeSet.title = movie.movieName;
attributeSet.contentDescription = movie.shortDescription ? movie.shortDescription : movie.longDescription;
attributeSet.thumbnailURL = [NSURL URLWithString: [movie posterURLStringWithWidth:100]];
the attributeSet is nil directly from start, so the last three lines does nothing. I have added the CoreSpotlight and MobileCoreService framework to the project and imported them in the same file. I have tried [[CSSearchableItemAttributeSet alloc] init] and this as well returns nil. I really can't figure out what I'm doing wrong. Using Xcode 7.0 beta 4. Any idea why it would return nil is highly appreciated!
From some trying back and forth I realised I did not have an iOS 9 beta installed on my phone which kind of explains why iOS 9 features does not work.. So, to answer my own question, you need to install iOS 9 (beta) when using CoreSpotlight.
In My iOS Application im using a class (DKTheme) to keep my fonts and images in a centralised place. my implementation looks like this.
+ (instancetype)theme {
static DKTheme *_theme = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_theme = [[DKTheme alloc] init];
});
return _theme;
}
- (id)init {
self = [super init];
if (self) {
[self setupTheme];
}
return self;
}
- (void)setupTheme {
// some code here
self.smallButtonFont = [UIFont fontWithName:#"Helvetica-Bold" size:13.0f];
//some code here
}
And when i run this code in device (iPhone 5C, iOS8.3 and iOS8.2), xcode hits breakpoint on the line self.smallButtonFont = [UIFont fontWithName:#"Helvetica-Bold" size:13.0f]; if i click continue execution button, application continue running without crashing and my font property(self.smallButtonFont) is successfully initialised.
and i noticed one more thing, i have several [UIFont fontWithName: size:]; calls and breakpoint hits only first time call.(if i comment the first one then next method call hits the break point). it is really annoying this breakpoint issue, any help would be thankful.
You have added a breakpoint exception in Xcode and configured it to break on all exception types, C++ and Objective-C. The problem is that C++ code sometimes uses exceptions for non-exceptional situations. It may use it just as a form of flow control or returning "failure" from a function.
Unless you have a specific C++ exception that you need to debug because it's actually causing a problem, probably best to configure that breakpoint to just break on Objective-C exceptions and not C++ exceptions. The C++ exceptions can be safely ignored.
This always happens when you added All Exceptions breakpoint. Here, you need to add only objective-c breakpoint.
Follow these steps:
Select Breakpoints debugger, right click on "All Exceptions".
Now select click "Edit Breakpoint"
Change Exception type to "Objective-c Exception"
At first. Of course it is exception breakpoint. You can add or delete it in "Breakpoints tab". My screenshot can help you with it.
Reason of generation this exceptions:
You have some default fonts in iOS. If you try to generate fond with unavailable font name. You see exception like this. Maybe in your code you use some another font name. I mean not only #"Helvetica-Bold". And now you have a question: How can i now, Is font available in my OS. You can print all available fonts using this method:
- (void)fontsList
{
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily) {
NSLog(#"Family name: %#", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont) {
NSLog(#" Font name: %#", [fontNames objectAtIndex:indFont]);
}
}
}
Best regards. And please add some info if you still have this problem.
If it's not that you've set up a breakpoint - it could be related to calling methods within init.
unsafe calls to self
Also see my notes about font caching and loading.
I had this problem as well, and solved it without changing my breakpoint settings. In my case, the problem was that my app had a framework whose info.plist file listed a provided font that was also listed as a provided font by the app itself (in the Fonts provided by application). Removing the duplicate fixed this issue.
I am updating an app for iOS 7. One of the changes is switching to the new drawInRect:withAttributes function instead of the deprecated drawInRect:withFont...
This was working fine on the iOS 7 beta, but today after upgrading to the latest iOS 7 version, the app crashes on the line:
[text drawInRect:theRect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:fontSz], NSFontAttributeName, color, NSForegroundColorAttributeName, nil]];
With the message:
*** -[NSStringDrawingTextStorage textContainerForAttributedString:containerSize:lineFragmentPadding:]: message sent to deallocated instance 0x187ed0f0
I tried running the Zombie instrument, which is not helpful at all neither the allocation nor the release of the object in question are in my code. Specifically I get the message:
An Objective-C message was sent to a deallocated 'NSStringDrawingTextStorage' object (zombie) at address: 0x169edc50.
And the malloc/release of the object are under the caller:
[NSStringDrawingTextStorage stringDrawingTextStorage]
What am I doing wrong?
I was able to work around this by trimming the leading whitespace (including newline characters) from the NSString I was rendering. Here's my category method:
- (NSString*)stringByTrimmingLeadingWhitespace
{
NSUInteger index = 0;
while((index < [self length]) && [[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember: [self characterAtIndex: index]])
{
index++;
}
return [self substringFromIndex: index];
}
Unfortunately if you must preserve the leading newline character(s), I do not have an alternative answer.
Car class
--------------
price
color
crash code is:
NSMutableArray *list = [[NSMutableArray alloc] init];
Car *car = [[Car alloc] init];
car.price = 10;
car.color = 1;
[list addObject:car];
// some code
[list removeAllObjects]; // Crash here
why crash, how can i resolve it.
app exit with nothing output
I dont know what you have in the "someCode" section in your segment. You first comment out that code and check if the app crashes. If still it crashes then only consider what I have given below. I mean you make sure there is nothing wrong with your code before going for workarounds :)
just try this code, and see if it crashes now.I know it doesn't make sense, but it happened to me once too. Once when array count was zero removeAllObjects crashed for me. I doubt an SDK bug somewhere there :(
if([list count]){
[list removeAllObjects];
}
Most likely you are releasing one or more of the objects in the array one too many times. When the NSMutableArray tries to release that object, it crashes because the object has already been disposed of.
I just ran into this same thing. In the dealloc method of my object I had:
-(void) dealloc
{
[super dealloc];// <--- le' culprit!
[Image_ID release];
[Image_Number release];
[Image_UID release];
[Series_ID release];
[Series_UID release];
[Study_UID release];
// <--- it should be here...
}
I moved [super dealloc] below all the releases..and my [.... removeAllObjects] worked fine..
At a guess, I'd say you're releasing list somewhere, and so your call to removeAllObjects is being sent to a deallocated instance. Impossible to be sure without a stack trace and some more detail, though—is it an EXC_BAD_ACCESS error or what?
Set the array property as Retain in interface section. Once I did same it worked for me. just try once.
In iPhone can we set the lock screen, wallpaper and ringtone programmatically?
If Yes, then please let me know how to set them?
This can all be done easily, but will be rejected by Apple.
The ringtone can be changed by altering com.apple.SpringBoard.plist, specifically the ringtone key.
The following code can be used to read the actual ringtone title of custom ringtones (synced by iTunes).
NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:#"/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
NSMutableDictionary *dictionary = [custDict objectForKey:#"Ringtones"];
NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSMutableDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:#"Name"];
cell.textLabel.text = name;
The Wallpapers can be overwritten at:
NSString *homePath1 = #"/private/var/mobile/Library/SpringBoard/HomeBackground.jpg";
NSString *homePath2 = #"/private/var/mobile/Library/SpringBoard/HomeBackgroundPortrait.jpg";
NSString *lockPath1 = #"/private/var/mobile/Library/SpringBoard/LockBackground.jpg";
NSString *lockPath2 = #"/private/var/mobile/Library/SpringBoard/LockBackgroundPortrait.jpg";
These examples were used in one of my Cydia apps. Theres not really much more to them, but these should get you going in the right direction.
The answer by WrightsCS stopped working at some point due to a change in iOS. Unfortunately, this is something you have to live with if you wish to use undocumented features.
If you still need to do this, for non-App Store apps only, this code works in iOS 9.3. It could stop working in any future iOS release, though. (see comment below: no longer working in iOS 10)
#import "SBSUIWallpaperPreviewViewController.h"
#import <dlfcn.h>
// open the private framework dynamically
void *handle = dlopen("/System/Library/PrivateFrameworks/SpringBoardUIServices.framework/SpringBoardUIServices", RTLD_NOW);
UIImage *wallpaper = [UIImage imageNamed: #"background.jpg"];
Class sbClass = NSClassFromString(#"SBSUIWallpaperPreviewViewController");
// we create a view controller, but don't display it.
// just use it to load image and set wallpaper
SBSUIWallpaperPreviewViewController *controller = (SBSUIWallpaperPreviewViewController*)[[sbClass alloc] initWithImage: wallpaper];
[controller setWallpaperForLocations: 3]; // 3 -> set both for lock screen and home screen
dlclose(handle);
You'll need to add the private API header to your project. You can usually find these online with a little searching, for example, here.
In the example above, [SBSUIWallpaperPreviewViewController setWallpaperForLocations:] is called with an argument of 3: 3 indicates the image should be used for both lock and home screens. 1 indicates Lock screen only. 2 indicates Home screen only.
For an explanation of why I open this framework up dynamically, see my related answer here.
I don't have an answer regarding ringtones. This really should be a separate question: completely different APIs at work.
use private api if you can
check PLStaticWallpaperImageViewController