I'm developing an app with Unity that uses Digital Ink Recognition of ML Kit to recognize handwriting.
To fetch ios plugin via unity, I use this script:
public static void Initialize(string languageTag = "en-US")
{
if (_instance != null)
{
return;
}
Debug.Log("Initializing...");
GameObject owner = new GameObject("HandwriteRecognitionIOSPluguin");
_instance = owner.AddComponent<HandwriteRecognitionIOSPluguin>();
_InitializeNew(languageTag);
}
from the above function will be directed to the objective-c script with the following script:
static DigitalInkRecognition* recognition = nil;
extern "C" void _InitializeNew(const char* languageTag)
{
if (recognition == nil)
recognition = [[DigitalInkRecognition alloc] init];
[recognition downloadModel];
}
the following is the script in the objective-c file
#import <GoogleMLKit/MLKit.h>
#interface DigitalInkRecognition : NSObject
#property(nonatomic) MLKDigitalInkRecognitionModel *model;
#property(nonatomic) MLKModelManager *modelManager;
#property(nonatomic) MLKDigitalInkRecognitionModelIdentifier *identifier;
#property(weak, nullable, nonatomic) id delegate;
#end
#implementation DigitalInkRecognition : NSObject
- (id)init
{
self = [super init];
_modelManager = [MLKModelManager modelManager];
_delegate = self;
__weak __typeof(self) weakSelf = self;
[NSNotificationCenter.defaultCenter
addObserverForName:MLKModelDownloadDidSucceedNotification
object:nil
queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *notification) {
__typeof(self) strongSelf = weakSelf;
if (strongSelf == nil) {
NSLog(#"self == nil handling download success notification");
return;
}
if ([notification.userInfo[MLKModelDownloadUserInfoKeyRemoteModel]
isEqual:strongSelf.model]) {
[strongSelf.delegate displayMessage:#"Model download succeeded"];
}
}];
[NSNotificationCenter.defaultCenter
addObserverForName:MLKModelDownloadDidFailNotification
object:nil
queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *notification) {
__typeof(self) strongSelf = weakSelf;
if (strongSelf == nil) {
NSLog(#"self == nil handling download fail notification");
return;
}
if ([notification.userInfo[MLKModelDownloadUserInfoKeyRemoteModel]
isEqual:strongSelf.model]) {
[strongSelf.delegate displayMessage:#"Model download failed"];
}
}];
NSString *language = [[NSLocale preferredLanguages] firstObject];
self.identifier =
[MLKDigitalInkRecognitionModelIdentifier modelIdentifierFromLanguageTag:language error:nil];
[self displayMessage:language];
if (self.identifier == nil) {
self.identifier = [MLKDigitalInkRecognitionModelIdentifier modelIdentifierFromLanguageTag:#"en" error:nil];
}
return self;
}
- (IBAction)downloadModel {
if ([self.modelManager isModelDownloaded:self.model]) {
[self.delegate displayMessage:#"Model is already downloaded"];
return;
}
[self.delegate displayMessage:#"Starting download"];
self.model = [[MLKDigitalInkRecognitionModel alloc] initWithModelIdentifier:self.identifier];
self.modelManager = [MLKModelManager modelManager];
//ERROR HERE
[self.modelManager downloadModel:self.model
conditions:[[MLKModelDownloadConditions alloc]
initWithAllowsCellularAccess:YES
allowsBackgroundDownloading:YES]];
}
- (void)displayMessage:(NSString *)message {
NSLog(#"LOG MESSAGE :: %#", message);
}
#end
When entering the 'downloadModel' function, the script will error with the following message:
2022-01-24 13:11:33.828766+0700 appdev[734:210369] +[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10
2022-01-24 13:11:33.868910+0700 appdev[734:210369] Uncaught exception: NSInvalidArgumentException: +[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10
(
0 CoreFoundation 0x00000001804c6d50 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 597328
1 libobjc.A.dylib 0x000000019782b6a8 objc_exception_throw + 56
2 CoreFoundation 0x00000001805966b0 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 1447600
3 CoreFoundation 0x0000000180460f6c 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 180076
4 CoreFoundation 0x00000001804601dc _CF_forwarding_prep_0 + 92
5 UnityFramework 0x00000001081933ac -[MLKDigitalInkRecognitionLogger logEvent:withName:] + 92
6 UnityFramework 0x00000001081949bc -[MLKDigitalInkLogEvent log] + 424
7 UnityFramework 0x000000010819752c -[MLKDigitalInkRecognitionModelManager downloadModel:conditions:] + 328
8 UnityFramework 0x0000000108132e28 -[MLKModelManager downloadModel:conditions:] + 224
9 UnityFramework 0x0000000108124964 -[DigitalInkRecognition downloadModel] + 588
10 UnityFramework 0x000000010945a8a4 HandwriteRecognitionIOSPluguin_Initialize_mC4FA5B192BDF0E20E606D3DC32DFB3A71C363767 + 288
11 UnityFramework 0x000000010945b7cc IOSHandwritingManager_U3CStartU3Eb__17_0_m0444198A2E9188E1DC9F9A84E34AC1E1C22A03C5 + 180
12 UnityFramework 0x0000000109556bc4 UnityAction_Invoke_mC9FF5AA1F82FDE635B3B6644CE71C94C31C3E71A + 276
13 UnityFramework 0x000000010955d9cc UnityEvent_Invoke_mB2FA1C76256FE34D5E7F84ABE528AC61CE8A0325 + 348
14 UnityFramework 0x000000010952b6d8 EventFunction_1_Invoke_m7899B7663B08CD474B8FADD9D85FF446CD839FE6_gshared + 504
15 UnityFramework 0x00000001094661f0 ExecuteEvents_Execute_TisRuntimeObject_mDA4CD02F963B6939F8D079993DC2DCD75AB524DD_gshared + 308
16 UnityFramework 0x0000000109595a7c StandaloneInputModule_ProcessTouchPress_m74A52DA64B9C5EB8B5A38889F25BFEAFC284FB51 + 1216
17 UnityFramework 0x0000000109595060 StandaloneInputModule_ProcessTouchEvents_mFEED66642E804A218DD34A9C5F0F8EAA5CA3B019 + 248
18 UnityFramework 0x0000000109594d9c StandaloneInputModule_Process_mBF40EA3762B85C417E6F88D531174D05A7FFCE75 + 72
19 UnityFramework 0x00000001080f50ac _Z65RuntimeInvoker_TrueVoid_t22962CB4C05B1D89B55A6E1139F0E87A90987017PFvvEPK10MethodInfoPvPS4_ + 20
20 UnityFramework 0x0000000109440e5c _ZN6il2cpp2vm7Runtime6InvokeEPK10MethodInfoPvPS5_PP15Il2CppException + 116
21 UnityFramework 0x00000001090fa620 _Z23scripting_method_invoke18ScriptingMethodPtr18ScriptingObjectPtrR18ScriptingArgumentsP21ScriptingExceptionPtrb + 116
22 UnityFramework 0x0000000109105268 _ZN19ScriptingInvocation6InvokeEP21ScriptingExceptionPtrb + 116
23 UnityFramework 0x0000000109110954 _ZN13MonoBehaviour16CallUpdateMethodEi + 300
24 UnityFramework 0x0000000108f96668 _ZN20BaseBehaviourManager12CommonUpdateI16BehaviourManagerEEvv + 224
25 UnityFramework 0x000000010905e588 _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 88
26 UnityFramework 0x000000010905e5bc _Z17ExecutePlayerLoopP22NativePlayerLoopSystem + 140
27 UnityFramework 0x000000010905e824 _Z10PlayerLoopv + 356
28 UnityFramework 0x0000000109255784 _ZL19UnityPlayerLoopImplb + 224
29 UnityFramework 0x00000001080be714 UnityRepaint + 140
30 UnityFramework 0x00000001080be5f0 -[UnityAppController(Rendering) repaintDisplayLink] + 88
31 QuartzCore 0x0000000183f5cd1c 36E47EF8-38B9-36C6-95B4-7AF8527D7E9D + 64796
32 QuartzCore 0x0000000183f634e8 36E47EF8-38B9-36C6-95B4-7AF8527D7E9D + 91368
33 CoreFoundation 0x000000018043f69c 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 42652
34 CoreFoundation 0x000000018047f4ec 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 304364
35 CoreFoundation 0x0000000180482adc 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 318172
36 CoreFoundation 0x00000001804400f0 7A0C7B81-A5B6-36A6-B41C-C7C790076454 + 45296
37 CoreFoundation 0x0000000180452e1c CFRunLoopRunSpecific + 572
38 GraphicsServices 0x00000001a07e19a0 GSEventRunModal + 160
39 UIKitCore 0x0000000182c86600 D8869DEE-E238-3284-8C9A-623313659320 + 5162496
40 UIKitCore 0x0000000182a1bb08 UIApplicationMain + 2028
41 UnityFramework 0x00000001080bd0f0 -[UnityFramework runUIApplicationMainWithArgc:argv:] + 108
42 appdev 0x00000001001e7e84 main + 68
43 dyld 0x0000000101e34250 start + 444
)
2022-01-24 13:11:33.870345+0700 appdev[734:210369] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10'
*** First throw call stack:
(0x1804c6d3c 0x19782b6a8 0x1805966b0 0x180460f6c 0x1804601dc 0x1081933ac 0x1081949bc 0x10819752c 0x108132e28 0x108124964 0x10945a8a4 0x10945b7cc 0x109556bc4 0x10955d9cc 0x10952b6d8 0x1094661f0 0x109595a7c 0x109595060 0x109594d9c 0x1080f50ac 0x109440e5c 0x1090fa620 0x109105268 0x109110954 0x108f96668 0x10905e588 0x10905e5bc 0x10905e824 0x109255784 0x1080be714 0x1080be5f0 0x183f5cd1c 0x183f634e8 0x18043f69c 0x18047f4ec 0x180482adc 0x1804400f0 0x180452e1c 0x1a07e19a0 0x182c86600 0x182a1bb08 0x1080bd0f0 0x1001e7e84 0x101e34250)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[FBMLOnDeviceDigitalInkLogEvent firebaseMlSdkLogEventExt]: unrecognized selector sent to class 0x109df1f10'
(lldb)
on error, script goes to file 'main.mm' line 26 ([ufw runUIApplicationMainWithArgc: argc argv: argv];). The following is the contents of the 'main.mm' file:
#include <UnityFramework/UnityFramework.h>
UnityFramework* UnityFrameworkLoad()
{
NSString* bundlePath = nil;
bundlePath = [[NSBundle mainBundle] bundlePath];
bundlePath = [bundlePath stringByAppendingString: #"/Frameworks/UnityFramework.framework"];
NSBundle* bundle = [NSBundle bundleWithPath: bundlePath];
if ([bundle isLoaded] == false) [bundle load];
UnityFramework* ufw = [bundle.principalClass getInstance];
if (![ufw appController])
{
// unity is not initialized
[ufw setExecuteHeader: &_mh_execute_header];
}
return ufw;
}
int main(int argc, char* argv[])
{
#autoreleasepool
{
id ufw = UnityFrameworkLoad();
[ufw runUIApplicationMainWithArgc: argc argv: argv];
return 0;
}
}
What can I do to solve the problem I'm having?
Thanks in advance for any idea.
Related
I'm trying to update my project for iOS13. I'm using UIScrollSlidingPages library in my application project.
I put this library in my UIViewController like below. I put my custom view in data source.
- (TTSlidingPage *)pageForSlidingPagesViewController:(TTScrollSlidingPagesController_Custom*)source atIndex:(int)index{
PhotoGalleryItemView *item = [[PhotoGalleryItemView alloc] initPhotoGalleryItem:[restaurantData.Galeri objectAtIndex:index] ParentViewController:self];
item.view.frame = _ViewPhotoContainer.frame;
TTSlidingPage *slidingPage = [[TTSlidingPage alloc] initWithContentViewController:item];
return slidingPage;
}
But when i run the app it crash despite i reload data with DispatchQueue Main Async like these solutions.
2019-11-08 09:42:22.760428+0300 GastroClub[5790:35896] WARNING: GoogleAnalytics 3.17 void GAIUncaughtExceptionHandler(NSException *) (GAIUncaughtExceptionHandler.m:48): Uncaught exception: <PhotoGalleryItemView: 0x7f9eb1782db0> returned nil from -traitCollection, which is not allowed.
2019-11-08 09:42:22.925971+0300 GastroClub[5790:35896] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
2019-11-08 09:42:22.988883+0300 GastroClub[5790:35896] *** Assertion failure in UITraitCollection * _Nonnull _UIGetCurrentFallbackTraitCollection(void)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3900.12.15/_UIFallbackEnvironment.m:91
2019-11-08 09:42:22.990119+0300 GastroClub[5790:35896] *** WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: <NSInternalInconsistencyException> <PhotoGalleryItemView: 0x7f9eb1782db0> returned nil from -traitCollection, which is not allowed.
2019-11-08 09:42:27.776557+0300 GastroClub[5790:35896] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<PhotoGalleryItemView: 0x7f9eb1782db0> returned nil from -traitCollection, which is not allowed.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c4eda8 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff256c9c2a -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4 UIKitCore 0x00007fff474abd67 _UIGetCurrentFallbackTraitCollection + 962
5 UIKitCore 0x00007fff47d00909 UIViewCommonInitWithFrame + 644
6 UIKitCore 0x00007fff47d00647 -[UIView initWithFrame:] + 98
7 UIKitCore 0x00007fff47cde48f -[UIImageView initWithFrame:] + 62
8 UIKitCore 0x00007fff47cffe99 -[UIView init] + 44
9 GastroClub 0x000000010816d313 -[UIImageView(Preloader) addPreloder] + 131
10 GastroClub 0x000000010816dcf6 -[UIImageView(Preloader) setImageWithURL_ShowPreloader:placeholderImage:options:progress:completed:] + 182
11 GastroClub 0x000000010816db69 -[UIImageView(Preloader) setImageWithURL_ShowPreloader:] + 105
12 GastroClub 0x00000001080c29f8 -[PhotoGalleryItemView viewDidLoad] + 200
13 UIKitCore 0x00007fff471cdb45 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 83
14 UIKitCore 0x00007fff471d2a9e -[UIViewController loadViewIfRequired] + 1084
15 UIKitCore 0x00007fff471d2ebb -[UIViewController view] + 27
16 UIScrollSlidingPages 0x000000010a06f2fd -[TTSlidingPage setContentViewController:] + 93
17 UIScrollSlidingPages 0x000000010a06f18b -[TTSlidingPage initWithContentViewController:] + 139
18 GastroClub 0x000000010806b32d -[RestaurantDetailViewController pageForSlidingPagesViewController:atIndex:] + 429
19 UIScrollSlidingPages 0x000000010a06b6cf -[TTScrollSlidingPagesController reloadPages] + 3455
20 GastroClub 0x0000000108060d42 __48-[RestaurantDetailViewController addPhotoSlider]_block_invoke + 50
21 libdispatch.dylib 0x000000010abc6dd4 _dispatch_call_block_and_release + 12
22 libdispatch.dylib 0x000000010abc7d48 _dispatch_client_callout + 8
23 libdispatch.dylib 0x000000010abd5de6 _dispatch_main_queue_callback_4CF + 1500
24 CoreFoundation 0x00007fff23bb1df9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
25 CoreFoundation 0x00007fff23baca59 __CFRunLoopRun + 2329
26 CoreFoundation 0x00007fff23babe16 CFRunLoopRunSpecific + 438
27 GraphicsServices 0x00007fff38438bb0 GSEventRunModal + 65
28 UIKitCore 0x00007fff4784fb68 UIApplicationMain + 1621
29 GastroClub 0x000000010801b900 main + 112
30 libdyld.dylib 0x00007fff51a1dc25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Then i tried to fix that with this solution. I put this method in my custom view like below:
#interface PhotoGalleryItemView (){
GCGaleri *galleryItem;
}
#property (weak, nonatomic) IBOutlet UIImageView *IMGViewGallery;
#end
#implementation PhotoGalleryItemView
- (id)initPhotoGalleryItem:(GCGaleri*)GalleryItem ParentViewController :(RestaurantDetailViewController*)ParentViewController {
if (self) {
galleryItem = GalleryItem;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[_IMGViewGallery setImageWithURL_ShowPreloader:[NSURL URLWithString:galleryItem.Foto]];
_IMGViewGallery.clipsToBounds = YES;
_IMGViewGallery.contentMode = UIViewContentModeScaleAspectFill;
}
// I put here
- (UITraitCollection *)traitCollection
{
if (#available(iOS 13.0, *)) {
[UITraitCollection setCurrentTraitCollection:[[UITraitCollection alloc]init]];
} else {
// Fallback on earlier versions
};
return [[UITraitCollection alloc]init];
}
#end
After that, i run my app it crash with these errors:
2019-11-08 10:03:40.570894+0300 GastroClub[5914:42170] [TraitCollection] Class PhotoGalleryItemView overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.
2019-11-08 10:03:40.571987+0300 GastroClub[5914:42170] [Assert] Current fallback trait collection contains one or more unspecified traits: {(
"_UITraitNameDisplayGamut",
"_UITraitNameDebugHighlight",
"_UITraitNameDisplayScale",
"_UITraitNameDisplayCornerRadius",
"_UITraitNamePresentationSemanticContext",
"_UITraitNameUserInterfaceLevel",
"_UITraitNameVibrancy",
"_UITraitNameLegibilityWeight",
"_UITraitNamePreferredContentSizeCategory",
"_UITraitNameAccessibilityContrast",
"_UITraitNameTouchLevel",
"_UITraitNameSemanticContext"
)}; traitCollection: <UITraitCollection: 0x600001984600; >; currentFallbackEnvironment: <PhotoGalleryItemView: 0x7fdeb1e9cac0>
How can i fix that issue? I can not update my library because it is no longer in active development.
I found the solution. When I slidingPage initiate then I show a preloader. My crash has occurred when I show the preloader. When I put my preloader in DispatchAsyncAfter like below I could fix my error:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self addPreloder];
__weak typeof(self) weakSelf = self;
[self sd_setImageWithURL:url
placeholderImage:placeholder
options:options
progress:progressBlock
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageUrl) {
if (completedBlock) {
completedBlock(image, error, cacheType, imageUrl);
}
dispatch_async(dispatch_get_main_queue(), ^(void) {
if (weakSelf.preloding) {
dispatch_async(dispatch_get_main_queue(), ^(void) {
[weakSelf.preloding stopAnimating];
[weakSelf.preloding removeFromSuperview];
[weakSelf removeActivityIndicator];
});
}
});
}
];
});
In swift 5 it work for me
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(0.5 * Double(NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: {
// your code here
})
my app is crashed when the user tapped on a marker (GMSMapVIew: didTapMarker) and myApp works good in 99% of the time, But sometimes it shows a crash on crashlytics. And it's so random occurred.
The crash report shows the following.
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000002f6ce97f4
-[BadgerMapView mapView:didTapMarker:]
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1f025653c objc_msgSend + 28
1 Badger 0x104d3af84 -[BadgerMapView mapView:didTapMarker:] + 1784 (BadgerMapView.m:1784)
2 CoreFoundation 0x1f106b900 __invoking___ + 144
3 CoreFoundation 0x1f0f4d4d0 -[NSInvocation invoke] + 292
4 CoreFoundation 0x1f0f4e104 -[NSInvocation invokeWithTarget:] + 60
5 Badger 0x104e940e0 -[GMSDelegateForward forwardInvocation:] + 4339744992
6 CoreFoundation 0x1f10697c0 ___forwarding___ + 636
7 CoreFoundation 0x1f106b75c _CF_forwarding_prep_0 + 92
8 Badger 0x104ea01fc -[GMSMapView didTapMarker:] + 20436
9 Badger 0x104eb8a88 -[GMSMarker wasTapped] + 120928
10 UIKitCore 0x21d1c3868 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64
11 UIKitCore 0x21d1cba70 _UIGestureRecognizerSendTargetActions + 124
12 UIKitCore 0x21d1c9414 _UIGestureRecognizerSendActions + 316
13 UIKitCore 0x21d1c8940 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 760
14 UIKitCore 0x21d1bca1c _UIGestureEnvironmentUpdate + 2180
15 CoreFoundation 0x1f0ff55f8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
16 CoreFoundation 0x1f0ff0320 __CFRunLoopDoObservers + 412
17 CoreFoundation 0x1f0ff089c __CFRunLoopRun + 1228
18 CoreFoundation 0x1f0ff00b0 CFRunLoopRunSpecific + 436
19 GraphicsServices 0x1f31f079c GSEventRunModal + 104
20 UIKitCore 0x21d59a978 UIApplicationMain + 212
21 Badger 0x104cb863c main + 17 (main.m:17)
22 libdyld.dylib 0x1f0ab58e0 start + 4
Below is my code where the app is crash.
BadgerMapView.m:1784
if (![waypt isKindOfClass:[NSNull class]]) This is the line where i got crash
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
CLLocationCoordinate2D markerLocation = marker.position;
double tappedMarkerLattitude = markerLocation.latitude;
double tappedMarkerLongitude = markerLocation.longitude;
NSArray *waypoints =[MapViewController sharedInstance].wayPointsToShowOnRouteMode;
for (PlannerWaypoint *waypt in waypoints)
{
#try {
if (![waypt isKindOfClass:[NSNull class]]) {
if (![waypt isEqual:nil]) {
[MapViewController sharedInstance].currentWaypoint = waypt;
NSNumber *nextWayPointIndex = [MapViewController sharedInstance].currentWaypoint.modPosition;
NSNumber *prevWayPointIndex = [MapViewController sharedInstance].currentWaypoint.modPosition;
int value = [nextWayPointIndex intValue];
nextWayPointIndex = [NSNumber numberWithInt:value + 1];
NSUInteger nextWayPointIndexInt = [nextWayPointIndex integerValue];
prevWayPointIndex = [NSNumber numberWithInt:value - 1];
NSUInteger prevWayPointIndexInt = [prevWayPointIndex integerValue];
int waypointCount = (int)[waypoints count];
if (nextWayPointIndexInt > (waypointCount-1)) {
[MapViewController sharedInstance].nextWaypoint = [waypoints objectAtIndex:0];
}
else {
[MapViewController sharedInstance].nextWaypoint = [waypoints objectAtIndex:nextWayPointIndexInt];
}
if (prevWayPointIndexInt > (waypointCount-1)) {
[MapViewController sharedInstance].previousWaypoint = [waypoints objectAtIndex:(waypointCount-1)];
}
else {
[MapViewController sharedInstance].previousWaypoint = [waypoints objectAtIndex:prevWayPointIndexInt];
}
if([Utility isIphone] == NO) {
[[MapViewController sharedInstance] showMarkerSelectedAtMiddle:[MapViewController sharedInstance].currentWaypoint];
UIViewController *viewcontroller = [MenuViewController sharedInstance].presentedViewController;
if([viewcontroller.childViewControllers objectAtIndex:0]!=nil) {
RouteModeViewController *routeModeView = [viewcontroller.childViewControllers objectAtIndex:0];
[routeModeView.customerCardNameLabel setText:[MapViewController sharedInstance].waypointLabel];
}
} else {
UINavigationController *UINavController = (UINavigationController *)self.window.rootViewController.presentedViewController;
UIViewController *UIViewCon = [[UINavController viewControllers] lastObject];
if ([UIViewCon isKindOfClass:[MapViewController class]]) {
MapViewController *mapViewController = (MapViewController *)UIViewCon;
[mapViewController showMarkerSelectedAtMiddle:waypt];
}
}
[waypt release];
waypt = nil;
break;
}
}
} #catch (NSException *exception) {
NSLog(#"Exception in ProcessdidTapMarker: %#",exception);
[DeviceLoger log:[NSString stringWithFormat:#"Exception in ProcessdidTapMarker: %#",exception]];
}
}
return YES;
}
Does anybody have an idea?
Please help me, Because I'm facing this issue form a very long time
Thanks!
I have two modes - Mode 1 and Mode 2 which can be switched by a central button. Switch between modes allows user to see two different types of clustered annotations.
I can switch from Mode 1 to Mode 2 easily, but when I switch back to Mode 1 I'm getting this nasty error
-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fb1308cca50
I'm opening my code and in the TBClusteredAnnotations.m (script I'm using for clusterization). I have the following snippet of code relating to componentsSeparatedByString:
TBQuadTreeNodeData TBDataFromLine(NSString *line)
{
NSString *separator=#">>>>>>>>";
NSArray *components = [line componentsSeparatedByString: separator];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
TBUserInfo* userInfo = malloc(sizeof(TBUserInfo));
NSString *userName = [components[2] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
userInfo->userId = malloc(sizeof(char) * userName.length + 1);
strncpy(userInfo->userId, [userName UTF8String], userName.length + 1);
NSString *userId = [components [3] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
userInfo->userImage = malloc(sizeof(char) * userId.length + 1);
strncpy(userInfo->userImage, [userId UTF8String], userId.length + 1);
return TBQuadTreeNodeDataMake(latitude, longitude, userInfo);
}
but I'm loading my annotations with the following code in the MainViewController:
-(void)annotationsmode1:(NSMutableArray*)marr
{
if(marr.count>0)
{
NSMutableArray *newMarr1=[NSMutableArray new];
NSString *separatestuff=#">>>>>>>>";
for(NSMutableDictionary *dic in marr)
{
NSString *newStr=[NSString stringWithFormat:#"%#%#",[dic[#"latitude"] isEqualToString:#""]?#" ":dic[#"latitude"],separatestuff];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"longitude"] isEqualToString:#""]?#" ":dic[#"longitude"],separatestuff];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"id"] isEqualToString:#""]?#" ":dic[#"id"],separatestuff];
newStr=[NSString stringWithFormat:#"%#%#",newStr,[dic[#"image"] isEqualToString:#""]?#" ":dic[#"image"]];
[newMarr1 addObject:newStr];
}
//NSLog(#"NEW Array: %#",newMarr);
[self.coordinateQuadTree buildTree:newMarr1];
}
}
-(void)annotationsmode2:(NSMutableArray*)marr
{
if(marr.count>0)
{
NSMutableArray *newMarr=[NSMutableArray new];
NSString *separatestuff2=#">>>>>>>>";
for(NSMutableDictionary *dic in marr)
{
NSString *newStr=[NSString stringWithFormat:#"%#%#",[dic[#"lat"] isEqualToString:#""]?#" ":dic[#"lat"],separatestuff2];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"lang"] isEqualToString:#""]?#" ":dic[#"lang"],separatestuff2];
newStr=[NSString stringWithFormat:#"%#%#%#",newStr,[dic[#"id"] isEqualToString:#""]?#" ":dic[#"id"],separatestuff2];
newStr=[NSString stringWithFormat:#"%#%#",newStr,[dic[#"image"] isEqualToString:#""]?#" ":dic[#"image"]];
[newMarr addObject:newStr];
}
//NSLog(#"NEW Array: %#",newMarr);
[self.coordinateQuadTree buildTree:newMarr];
}
}
UPDATE: This is the block of code where the TBDataFromLine is used
- (void)buildTree:(NSMutableArray *)lines
{
#autoreleasepool {
NSInteger count = lines.count - 1;
TBQuadTreeNodeData *dataArray = malloc(sizeof(TBQuadTreeNodeData) * count);
for (NSInteger i = 0; i < count; i++) {
dataArray[i] = TBDataFromLine(lines[i]);
}
//TBBoundingBox world = TBBoundingBoxMake(19, -166, 72, -53);
TBBoundingBox world = TBBoundingBoxMake(0,0,100,100);
_root = TBQuadTreeBuildWithData(dataArray, count, world, 4);
}
}
I've been working on this issue for hours now and still have no clue.
UPDATE: Here is the debugger's log I'm getting
2015-06-20 19:40:23.759 MapProject[13426:395344] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary componentsSeparatedByString:]: unrecognized selector sent to instance 0x7fdf93775680'
*** First throw call stack:
(
0 CoreFoundation 0x0000000112699c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001121c3bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001126a10ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001125f713c ___forwarding___ + 988
4 CoreFoundation 0x00000001125f6cd8 _CF_forwarding_prep_0 + 120
5 MapProject 0x000000010f469ac4 TBDataFromLine + 84
6 MapProject 0x000000010f46a36f -[TBCoordinateQuadTree buildTree:] + 191
7 MapProject 0x000000010f3d2503 -[MMViewController findSpot:] + 771
8 UIKit 0x0000000110a52da2 -[UIApplication sendAction:to:from:forEvent:] + 75
9 UIKit 0x0000000110b6454a -[UIControl _sendActionsForEvents:withEvent:] + 467
10 UIKit 0x0000000110b63919 -[UIControl touchesEnded:withEvent:] + 522
11 UIKit 0x0000000110a9f998 -[UIWindow _sendTouchesForEvent:] + 735
12 UIKit 0x0000000110aa02c2 -[UIWindow sendEvent:] + 682
13 UIKit 0x0000000110a66581 -[UIApplication sendEvent:] + 246
14 UIKit 0x0000000110a73d1c _UIApplicationHandleEventFromQueueEvent + 18265
15 UIKit 0x0000000110a4e5dc _UIApplicationHandleEventQueue + 2066
16 CoreFoundation 0x00000001125cd431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
17 CoreFoundation 0x00000001125c32fd __CFRunLoopDoSources0 + 269
18 CoreFoundation 0x00000001125c2934 __CFRunLoopRun + 868
19 CoreFoundation 0x00000001125c2366 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x000000011444da3e GSEventRunModal + 161
21 UIKit 0x0000000110a51900 UIApplicationMain + 1282
22 MapProject 0x000000010f474c2f main + 111
23 libdyld.dy
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Add an Exception break point and it will take to exactly to that line where that crash is happening. Also check 'line' cause it is changed to dictionary but you code expect it
to be a string
There is no [] operator on NSArray or NSMutableArray.
You need this:
for (NSInteger i = 0; i < count; i++) {
dataArray[i] = TBDataFromLine([lines objectAtIndex:i]);
}
Using [] on NSArray* effectively acted like "lines" was really a pointer to an array of NSMutableArray instances, whereas you wanted to get one of the items out of the array to which it pointed.
I called method in another class (they are both singletons).
WebserviceHelper.h
#interface WebserviceHelper : NSObject {
int currentType;
NSString *SERVER_URL;
WebserviceManager *webService;
}
#property (nonatomic, assign) id delegate;
- (void)retrieveStudentwithCode:(NSString *)code {
currentType = STUDENT_TYPE;
NSString *param = [NSString stringWithFormat:#"token=uencom&cid=%#", code];
NSString *link = [NSString stringWithFormat:#"%#getStudentInfo", SERVER_URL];
[webService retrieveData:link withParameters:param];
}
After call webservice and get data it cached here in received data. I check and it works fine
but when it deliver to didFinishLoading error happen here
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)receivedData {
data = [NSMutableData new];
[data appendData:receivedData];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
//it carsh here
[delegate: data];
}
Call stack:
2014-08-20 10:39:05.187 School-Link[1030:60b] -[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420
2014-08-20 10:39:05.188 School-Link[1030:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WebserviceHelper :]: unrecognized selector sent to instance 0xa88a420'
*** First throw call stack:
(
0 CoreFoundation 0x01bf31e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018f08e5 objc_exception_throw + 44
2 CoreFoundation 0x01c90243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01be350b ___forwarding___ + 1019
4 CoreFoundation 0x01be30ee _CF_forwarding_prep_0 + 14
5 School-Link 0x00030c82 -[WebserviceManager connectionDidFinishLoading:] + 242
6 Foundation 0x016b9e49 ___NSURLConnectionDidFinishLoading_block_invoke + 40
7 Foundation 0x016507e1 __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 62
8 Foundation 0x014d8f5e -[NSURLConnectionInternalConnection invokeForDelegate:] + 119
9 Foundation 0x014d8ec6 -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 208
10 Foundation 0x014d8dd8 -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 76
11 Foundation 0x014d9188 _NSURLConnectionDidFinishLoading + 43
12 CFNetwork 0x02a3169f ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 111
13 CFNetwork 0x02a2f3de ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 104
14 CoreFoundation 0x01b94c69 CFArrayApplyFunction + 57
15 CFNetwork 0x02998441 _ZN19RunloopBlockContext7performEv + 155
16 CFNetwork 0x02a7a3f4 _ZThn16_N19RunloopBlockContext24multiplexerClientPerformEv + 20
17 CFNetwork 0x02998257 _ZN17MultiplexerSource7performEv + 299
18 CFNetwork 0x0299806c _ZN17MultiplexerSource8_performEPv + 76
19 CoreFoundation 0x01b7c77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
20 CoreFoundation 0x01b7c1d5 __CFRunLoopDoSources0 + 437
21 CoreFoundation 0x01b991ae __CFRunLoopRun + 910
22 CoreFoundation 0x01b989d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x01b987eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x0338d5ee GSEventRunModal + 192
25 GraphicsServices 0x0338d42b GSEventRun + 104
26 UIKit 0x005b0f9b UIApplicationMain + 1225
27 School-Link 0x00018f6d main + 141
28 libdyld.dylib 0x03026701 start + 1
29 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Try this, have a protocol declaration in WebserviceHelper.h like
#protocol studentDataDelegate <NSObject>
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
#end
WebserviceHelper.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
[self.delegate WebserviceHelper:self didStudentDataDownloadCompleteWithData:data];
}
so which ever class confirms to the above protocol should implement the delegate method like,
#interface RequestingDataClass : UIViewController <studentDataDelegate>
by doing this you will receive the warning that you have not implemented didStudentDataDownloadCompleteWithData:method so do it like
-(void)WebserviceHelper:(WebserviceHelper *)webserviceHelper didStudentDataDownloadCompleteWithData:(NSMutableData *)data;
{
webserviceHelper.delegate=self;
// Do something with the `data`
}
You do no show the declaration of the delegate, however this statement:
[delegate: data];
Should be:
[delegate haveSomeData:data];
(or something similar)
did you create protocol in your WebserviceHelper.h file like this?
#protocol WebserviceHelperDelegate <NSObject>
#required
-(void)reciveData:(NSData *)data;//or your method
#end
decleare a property
#property (nonatomic,strong) id <WebserviceHelperDelegate> delegate;
then call this method like
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[self stopPostingToWebservice];
//it carsh here
[self.delegate reciveData: data];
}
And implement this method from where you call webservice class and assign delegate
-(void)reciveData:(NSData *)data{
}
After adding the GoogleCast framework to the unit test target I'm getting the following exception right before the tests start to run. Apart from that the SDK is fully functional. I'd appreciate any ideas!
2014-02-25 18:03:08.475 otest[3786:303] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size
2014-02-25 18:03:08.593 otest[3786:303] *** Assertion failure in -[GCKPB_PBFieldDescriptor initWithFieldDescription:rootClass:], /Volumes/BuildData/pulse-data/agents/wpye22.hot/recipes/415961027/base/googlemac/iPhone/Chromecast/SDKv2/Protos/../../../../ThirdParty/ProtocolBuffers/objectivec/Classes/PBDescriptor.m:409
2014-02-25 18:03:08.596 otest[3786:303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to find enum descriptor PBFieldDescriptorProto_Label'
*** First throw call stack:
(
0 CoreFoundation 0x00b1d5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x007958b6 objc_exception_throw + 44
2 CoreFoundation 0x00b1d448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x00010fee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UnitTests 0x077205dd -[GCKPB_PBFieldDescriptor initWithFieldDescription:rootClass:] + 1640
5 UnitTests 0x0771f52c +[GCKPB_PBDescriptor allocDescriptorForClass:rootClass:fields:fieldCount:enums:enumCount:ranges:rangeCount:storageSize:wireFormat:] + 173
6 UnitTests 0x076e550f +[GCKPB_PBFieldDescriptorProto descriptor] + 179
7 UnitTests 0x077226b2 +[GCKPB_PBGeneratedMessage initialize] + 100
8 libobjc.A.dylib 0x00796275 _class_initialize + 599
9 libobjc.A.dylib 0x0079d0f1 lookUpImpOrForward + 158
10 libobjc.A.dylib 0x0079d04e _class_lookupMethodAndLoadCache3 + 55
11 libobjc.A.dylib 0x007a512f objc_msgSend + 139
12 SenTestingKit 0x201086c6 +[NSObject(SenTestRuntimeUtilities) senIsASuperclassOfClass:] + 74
13 SenTestingKit 0x2010879e +[NSObject(SenTestRuntimeUtilities) senAllSubclasses] + 154
14 SenTestingKit 0x20106fa0 +[SenTestSuite updateCache] + 42
15 SenTestingKit 0x201071cf +[SenTestSuite suiteForBundleCache] + 93
16 SenTestingKit 0x20107241 +[SenTestSuite testSuiteForBundlePath:] + 101
17 SenTestingKit 0x201061fb +[SenTestProbe specifiedTestSuite] + 294
18 SenTestingKit 0x20106467 +[SenTestProbe runTests:] + 177
19 libobjc.A.dylib 0x007a7737 +[NSObject performSelector:withObject:] + 70
20 otest 0x00002372 otest + 4978
21 otest 0x000025c4 otest + 5572
22 otest 0x000026a5 otest + 5797
23 otest 0x00002031 otest + 4145
24 libdyld.dylib 0x0165570d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
OCUnit's behaviour is to go through each class and hence call +initialize:
But this is not handled properly by GCKPB_PBGeneratedMessage and this bug has already been reported here.
While waiting for a fix, a temporary solution might be to mock GCKPB_PBGeneratedMessage's +initialize method in your unit tests with OCMock (or any other mocking framework) by adding the following code to your test class:
#import <OCMock/OCMock.h>
#interface GCKPB_PBGeneratedMessage : NSObject
#end
and
+ (void)initialize
{
id mockCastGeneratedMessage = [OCMockObject mockForClass:[GCKPB_PBGeneratedMessage class]];
[[mockCastGeneratedMessage stub] initialize];
}
Edit
As of iOS sender API v2.3.0 953, this is now fixed and this workaround is no longer required.
I came across a similar error when doing Unit Tests using Specta. I manually ignored the assert by creating my own assertion handler.
Defined in a helper class:
#define SPT_fail(...) \
SPTSpec *spec = [[SPTCurrentTestCase class] spt_spec]; \
NSString *message = [NSString stringWithFormat:__VA_ARGS__]; \
[SPTCurrentTestCase recordFailureWithDescription:message inFile:spec.fileName atLine:(int)spec.lineNumber expected:YES]; \
xxxLoggingAssertionHandler.m:
#implementation xxxLoggingAssertionHandler
+ (void)load {
[xxxLoggingAssertionHandler addHandler];
}
- (void)handleFailureInMethod:(SEL)selector
object:(id)object
file:(NSString *)fileName
lineNumber:(NSInteger)line
description:(NSString *)format, ... {
// ignore chromecast asserts only
NSString *selectorName = NSStringFromSelector(selector);
BOOL ignore = [selectorName isEqualToString:#"initWithFieldDescription:rootClass:"] || [selectorName isEqualToString:#"allocDescriptorForClass:rootClass:fields:fieldCount:enums:enumCount:ranges:rangeCount:storageSize:wireFormat:"];
if (!ignore) {
SPT_fail(#"NSAssert Failure: Method %# for object %# in %##%i", selectorName, object, fileName, line);
}
}
- (void)handleFailureInFunction:(NSString *)functionName
file:(NSString *)fileName
lineNumber:(NSInteger)line
description:(NSString *)format, ... {
SPT_fail(#"NSCAssert Failure: Function (%#) in %##%i", functionName, fileName, line);
}
+ (void)addHandler {
NSAssertionHandler *assertionHandler = [[xxxLoggingAssertionHandler alloc] init];
[[[NSThread currentThread] threadDictionary] setValue:assertionHandler
forKey:NSAssertionHandlerKey];
}
+ (void)removeHandler {
[[[NSThread currentThread] threadDictionary] setValue:nil
forKey:NSAssertionHandlerKey];
}
#end