WKWebview Crash frequently - objective-c

WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
config.mediaPlaybackRequiresUserAction = NO;
config.allowsInlineMediaPlayback = YES;
config.preferences.javaScriptEnabled=true;
config.allowsAirPlayForMediaPlayback = YES;
//Create new UIWebView for launched-app
WKWebView *appWebView = [[WKWebView new] initWithFrame:portalSizes configuration:config];
appWebView.navigationDelegate = self;
appWebView.UIDelegate=self;
appWebView.allowsLinkPreview=false;
appWebView.tag = WebView_Tag + launchedApps.count;
[appWebView setFrame:CGRectMake(appSize.width * launchedApps.count, 0, appSize.width, appSize.height)];
[appWebView setNavigationDelegate:self];
//[appWebView setAllowsInlineMediaPlayback:YES];
appWebView.scrollView.tag = ScrollView_Tag + launchedApps.count;
appWebView.scrollView.delegate = self;
[appWebView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM _webView:renderingProgressDidChange:]: unrecognized selector sent to instance 0x28254cab0'
terminating with uncaught exception of type NSException

The initialisation of variable appWebView is incorrect. [WKWebView new] is shortcut for [[WKWebView alloc] init] so your are potentially initialising the control twice.
Replace [[WKWebView new] initWithFrame:portalSizes configuration:config]
with [[WKWebView alloc] initWithFrame:portalSizes configuration:config] and check if this helps to prevent your code from crashing.
(Also using the tag property of a control to store the sum of a variable and a counter is a bit weird, why not store this all in a regular variable?)

Related

"unrecognized selector sent to instance" for NSArrayI

I have the following code which gives the "unrecognized selector sent to instance" error for the NSArray. I've not been able to figure this out and feel its something simple I'm missing here. I can post more if needed.
Quote *myQuote;
NSArray *myQuotes = theSubject.quotes;
//START LOOP HERE
for (myQuote in myQuotes){
NSLog(#" excerpt = %#", myQuote.excerpt);
NSLog(#" desc2 = %#", myQuote.desc2);
NSLog(#" quote_date = %#", myQuote.quote_date);
NSLog(#" myQuote = %#", myQuote);
I believe the problem is in this function which returns an array of Quotes:
- (NSArray *) getQuotesFromSubId:(NSInteger )subId {
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
self.quoteMaps = [appDelegate quoteMaps];
self.quotes = [appDelegate quotes];
//get the quote_ids from quote_map for this subject_id
NSString *stringOfSubjectId = [NSString stringWithFormat:#"%ld", (long)subId];
NSPredicate *filterSubjectId = [NSPredicate predicateWithFormat:#"subject_id == %#", stringOfSubjectId];
NSArray *quoteMapSection = [self.quoteMaps filteredArrayUsingPredicate:filterSubjectId];
NSMutableArray *quoteSection = [[NSMutableArray alloc] init];
NSArray *quoteToAdd = [[NSArray alloc] init];
for (QuoteMap *qm in quoteMapSection){
//get the quote_ids from quote_map for this subject_id
NSPredicate *filter = [NSPredicate predicateWithFormat:#"quote_id == %#", qm.quote_id];
quoteToAdd = [self.quotes filteredArrayUsingPredicate:filter];
[quoteSection addObject:quoteToAdd];
}
return quoteSection;
}
This is where I call it:
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *myQuotes = [appDelegate getQuotesFromSubId:selectedSubject.subject_id];
NSMutableArray *mArray = [appDelegate createMutableArray:myQuotes];
selectedSubject.quotes = mArray;
NSMutableArray *mutableArray = [appDelegate createMutableArray:myQuotes];
selectedSubject.quotes = mutableArray;
I got the following error
2016-02-23 00:24:20.383 Quotes[10631:3698114] -[__NSArrayI excerpt]: unrecognized selector sent to instance 0x15ebbeff0
2016-02-23 00:24:29.164 Quotes[10631:3698114] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI excerpt]: unrecognized selector sent to instance 0x15ebbeff0'
*** First throw call stack:
(0x182b55900 0x1821c3f80 0x182b5c61c 0x182b595b8 0x182a5d68c 0x100078b2c 0x1000642d0 0x187cb17f4 0x187cb1f8c 0x187b9fc90 0x187ba2e88 0x187977284 0x187883394 0x187882e90 0x187882d18 0x185259c00 0x10011dbb0 0x100123658 0x182b0cbb0 0x182b0aa18 0x182a39680 0x183f48088 0x1878b0d90 0x100040398 0x1825da8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
You are sending -excerpt to the members (myQuote) of myQuotes. The runtime says that NSArray (NSArrayI is an internal subclass) instances cannot understand -excerpt.
So the type of the member is NSArray. We cannot know, why you have instances of NSArray in the array MyQuotes, because we do not see that code. Likely that happened when you tried to add new quotes to the quotes property and incidentally added the whole array instead of its members.
To your edit:
This is wrong:
NSArray *quoteToAdd = [[NSArray alloc] init]; // This is an array. It identifier should be quote*s*ToAdd
// BTW: This above code is meaningless, because you do not need to create an array instance. Simply omit "[[NSArray alloc] init]". But this is not your problem.
for (QuoteMap *qm in quoteMapSection){
…
quoteToAdd = [self.quotes filteredArrayUsingPredicate:filter]; // filtered array returns an *array*
[quoteSection addObject:quoteToAdd]; // You add the *array* instead of the member of the array.
}
What you get back is an array. Then you add the array itself (not its members) to the existing array. As result you get an array that contains an array.
Simply change …
[quoteSection addObject:quoteToAdd];
… to:
[quoteSection addObjectsFromArray:quoteToAdd];
(And change the reference name to a plural form for better readability.)

NSMutable array error & showAnnotations

I have the following situation. I developed an app that frequently retrieves values for POI's that I want to show as annotations on a map. For this I wrote the method below, called after when a new set of POIs was retrieved:
-(void)showAnnotation{
[self removeAllPinsButUserLocation];
annotationArray = [[NSMutableArray alloc] init];
for (Poi *poi in [parser.pois allValues]) {
myAnnotation *arr = [[myAnnotation alloc] init];
arr.title = [NSString stringWithFormat:#"%# (%#)",poi.description, sensor.name];
arr.subtitle = [NSString stringWithFormat:#"%#, %# %#",poi.street, poi.postalcode, poi.city];
arr.coordinate = CLLocationCoordinate2DMake(poi.lattitude, poi.longitude);
[annotationArray addObject:arr];
arr = nil;
}
[self.mapView addAnnotations:annotationArray];
[self.mapView showAnnotations:annotationArray animated:NO];
}
Problem is that I get an error (Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection <__NSArrayM: 0x14ebe9b0> was mutated while being enumerated.')
However only if I set animated:NO in the last line, but not when set to animated:YES...
Does anyone have an answer for this?
Thanks for replying!
Eelco

UIRefreshControl - Terminating app due to uncaught exception

I implemented UIRefreshControl on a Table View inside a UITableViewController. Today my friend (first tester) was playing with the app and he was able to make crash by pulling to refresh and while it's refreshing, pulling on it again very quickly a couple of times. I know it's not a common thing to do but I can recreate it very easily. I'm guessing there's something wrong with the way I'm implementing the refresh control since I tried to recreate it with the Gmail app and it didn't crash.
This is the error I get:
[1008:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSCFConstantString stringByAppendingString:]: nil argument'
* First throw call stack:
(0x343f32a3 0x3c08d97f 0x343f31c5 0x34c5c5e1 0x496b5 0x3624654d 0x3622b313 0x362427cf 0x361fe803 0x35fa8d8b 0x35fa8929 0x35fa985d 0x35fa9243 0x35fa9051 0x35fa8eb1 0x343c86cd 0x343c69c1 0x343c6d17 0x34339ebd 0x34339d49 0x37efb2eb 0x3624f301 0x46da5 0x3c4c4b20)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Under ViewDidLoad
// pull to refresh
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(updateTableView:) forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:refreshControl];
And this is the updateTableView method:
- (void)updateTableView:(id)sender {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM d, h:mm:ss a"];
NSString *lastUpdated = [NSString stringWithFormat:#"Last updated on %#", [formatter stringFromDate:[NSDate date]]];
self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated];
if(topOptions.selectedSegmentIndex == 0) {
//fetch the feed
_feed = [[FetchData alloc] initFromURLWithString:#"some json file" completion:^(JSONModel *model, JSONModelError *err) {
[self.tableView reloadData];
[(UIRefreshControl *)sender endRefreshing];
}];
} else if (topOptions.selectedSegmentIndex == 1) {
//fetch the feed
_feed = [[FetchData alloc] initFromURLWithString:#"another json file" completion:^(JSONModel *model, JSONModelError *err) {
[self.tableView reloadData];
[(UIRefreshControl *)sender endRefreshing];
}];
}
}
I'm guessing (from the nil argument) that by doing the refresh request many times it reaches a point that it can't find a value? I'm kind of new at this so any idea is really appreciated.
If you need any other part of the code let me know.

App crash after '

My application is crashing when a ' appears in the title of the JSON code i'm parsing.
This line is loading the title's:
[[cell textLabel] setText:[item objectForKey:#"title"]];
JSON:
NSString *jsonString = [NSString
stringWithContentsOfURL:[NSURL URLWithString:#"**test.php"]
encoding:NSStringEncodingConversionAllowLossy
error:nil];
// Create parser
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
parser = nil;
// Set tableData
[self setTableData:[results objectForKey:#"items"]];
Crash:
tableData NSArray * 0x00000001
2012-04-10 10:29:11.446 *[21222:f803] -[NSNull isEqualToString:]:
unrecognized selector sent to instance 0x146ace8 2012-04-10
10:29:11.447 *[21222:f803] * Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[NSNull
isEqualToString:]: unrecognized selector sent to instance 0x146ace8'
* First throw call stack: (0x13d4022 0x1565cd6 0x13d5cbd 0x133aed0 0x133acb2 0x15e0ff 0x2b10 0xb8c54 0xb93ce 0xa4cbd 0xb36f1 0x5cd21
0x13d5e42 0x1d8c679 0x1d96579 0x1d1b4f7 0x1d1d3f6 0x1db81ce 0x1db8003
0x13a8936 0x13a83d7 0x130b790 0x130ad84 0x130ac9b 0x12bd7d8 0x12bd88a
0x1e626 0x1ded 0x1d55) terminate called throwing an exception(lldb)
The key part of that crash info is: unrecognized selector sent to instance ... [NSNull isEqualToString:]
It looks like your JSON contains null somewhere that you are expecting a string. Later on, probably inside of setTableData: you will be doing something like this:
NSString* whatever = [items objectForKey:#"whatever"];
if([whatever isEqualToString:#"hello"]){
...
}
And that will crash, because the whatever variable contains NSNull, not an NSString like you were expecting.

Error: "-[UIView setHostedGraph:]: unrecognized selector" while executing the core plot in iPhone app

I get the below error when I try to compile the below code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setHostedGraph:]: unrecognized selector sent to instance 0x6768c10'
Code:
UIView *ChartView;
ChartView = [[UIView alloc] init];
graph = [[CPXYGraph alloc] initWithFrame: ChartView.bounds];
CPGraphHostingView *hostingView = (CPGraphHostingView *)ChartView;
hostingView.hostedGraph = graph;
What could be wrong?
You're casting a UIView instance (which does not respond to -setHostedGraph:) to a CPGraphHostingView. - This will not work.
You'll need to create an actual CPGraphHostingView object, then invoke -setHostedGraph: on it.
So, your code should look like this:
CGRect someFrame = ...;
CPGraphHostingView *hostingView = [[CPGraphHostingView alloc] initWithFrame:someFrame];
graph = [[CPXYGraph alloc] initWithFrame: hostingView.bounds];
hostingView.hostedGraph = graph;