Reputation: 111
I hint error as below when i pass in data into PushNotificationManager.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI un_stringWithMaxLength:]: unrecognized selector sent to instance 0x604000018550'
Here is my code:-
[self.manager GET:@"http://api.xxxx.com/api/promotion/1" parameters:nil progress:nil success:^(NSURLSessionDataTask *task, id responseObject) {
json_promotion = responseObject;
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self];
NSString *strProTitle = [json_promotion valueForKey:@"title"];
NSLog(@"strProTitle - %@",strProTitle);
//Will get string "Promotion Today!" which is CORRECT
//If i put NSString *strProTitle = @"testing here", error will not appear.
[[PushNotificationManager sharedInstance]graphicsPushNotificationWithTitle:strProTitle subTitle:@"text here" body:@"desc here" identifier:@"2-1" fileName:@"Graphics.jpg" timeInterval:3 repeat:NO];
Any idea? Please help.
Upvotes: 0
Views: 83
Reputation: 1957
Your error message is basically telling you are passing an array instead of string.
I am guessing this is happening becuase valueForKey
is returning an array. While parsing an object it's better to type check.
You could instead use json_promotion[0][@"title"]
.
If you want a better syntax I would use the following
NSString *strProTitle;
if([json_promotion isKindOfClass:[NSArray class]] {
id obj = json_promotion[0][@"title"]
if ([obj isKindOfClass: [NSString class]]) {
strProTitle = obj;
}
}
Upvotes: 1