UITraitCollection getter, which is not supported on iOS13 - ios

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
})

Related

Application tried to present a nil modal view controller on target in React Native

there
I'm trying to open native modal on iOS in React Native.
The result I wanted was a screen like the one below.
But I got the following error:
Thread 1: "Application tried to present a nil modal view controller on target <UIViewController: 0x7f904f811290>.
I don't know much about object-c, so I searched the internet for it, and eventually asked a question.
How can I solve it?
Here is one of the stack traces:
*** First throw call stack:
(
0 CoreFoundation 0x000000010a5a1bb4 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x000000010a2abbe7 objc_exception_throw + 48
2 UIKitCore 0x000000011b2c5b95 -[UIViewController _presentViewController:withAnimationController:completion:] + 6177
3 UIKitCore 0x000000011b2c6520 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
4 UIKitCore 0x000000011b2c6856 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 519
5 UIKitCore 0x000000011b2c647e -[UIViewController _presentViewController:animated:completion:] + 173
6 UIKitCore 0x000000011b2c690c -[UIViewController presentViewController:animated:completion:] + 155
7 Awesome 0x0000000100243d7b __19-[Buzzvil openFeed]_block_invoke + 203
8 libdispatch.dylib 0x000000010e7d6a28 _dispatch_call_block_and_release + 12
9 libdispatch.dylib 0x000000010e7d7c0c _dispatch_client_callout + 8
10 libdispatch.dylib 0x000000010e7e6376 _dispatch_main_queue_callback_4CF + 1195
11 CoreFoundation 0x000000010a50f85d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
12 CoreFoundation 0x000000010a50a0ba __CFRunLoopRun + 2772
13 CoreFoundation 0x000000010a509103 CFRunLoopRunSpecific + 567
14 GraphicsServices 0x000000011316ccd3 GSEventRunModal + 139
15 UIKitCore 0x000000011ba6be63 -[UIApplication _run] + 928
16 UIKitCore 0x000000011ba70a53 UIApplicationMain + 101
17 Awesome 0x0000000100244518 main + 104
18 dyld 0x00000001089d5e1e start_sim + 10
19 ??? 0x00000002005f64fe 0x0 + 8596186366
20 ??? 0x0000000000000003 0x0 + 3
)
Here is my problematic code ( Buzzvil.m )
#import "Buzzvil.h"
#import <React/RCTLog.h>
#import BuzzAdBenefit;
#interface Buzzvil ()
#property (nonatomic, strong, readonly) BZVBuzzAdFeed *buzzAdFeed;
#end
#implementation Buzzvil
RCT_EXPORT_MODULE();
- (void) viewDidLoad {
[super viewDidLoad];
_buzzAdFeed = [BZVBuzzAdFeed feedWithBlock:^(BZVBuzzAdFeedBuilder * _Nonnull builder) {}];
}
RCT_EXPORT_METHOD(logEvent:(NSString *)name location:(NSString *)location)
{
RCTLogInfo(#"fire event xocde log %# at %#", name, location);
}
RCT_EXPORT_METHOD(messageEvent:(RCTResponseSenderBlock)callback)
{
callback(#[#"hello from native ios"]);
}
RCT_EXPORT_METHOD(setUserEvent:(NSString *)userId gender:(NSString *)gender birth:(NSString *)birth)
{
RCTLogInfo(#"id= %# <> gender= %# <> birth= %#", userId, gender, birth);
NSString *male = #"M";
[BuzzAdBenefit loginWithBlock:^(BZVLoginRequestBuilder * _Nonnull builder) {
builder.userId = userId;
builder.birthYear = [birth intValue];
builder.gender = [gender isEqualToString:male] ? BZVUserGenderMale : BZVUserGenderFemale;
} onSuccess:^{
RCTLogInfo(#"on Success!!");
} onFailure:^(NSError * _Nonnull error) {
RCTLogInfo(#"on Error!!");
}];
}
// An error occurs when the function below is executed.
RCT_EXPORT_METHOD(openFeed)
{
dispatch_async(dispatch_get_main_queue(), ^{
UIViewController *rootviewcontroller= [UIApplication sharedApplication].keyWindow.rootViewController;
BZVFeedViewController *feedViewController = [self->_buzzAdFeed viewController];
[rootviewcontroller presentViewController:feedViewController animated:YES completion:nil];
});
}
#end
and here is Buzzvil.h file
#import <React/RCTBridgeModule.h>
#interface Buzzvil : UIViewController<RCTBridgeModule>
#property(nonatomic, strong) UIViewController *rootViewController;
#end

MLKit Digital Ink Recognition in unity error when download model

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.

Why UIView's setFrame is not same as UILabel's setFrame

In order to detect the behavior of refresh UI on background thread,I used the third-part library ODUIThreadGuard.
This lib is based on hook UIView's setNeedsLayout、setNeedsDisplay、setNeedsDisplayInRect selector.
When I tested it, I found that UILabel's setFrame: on background thread can be detected but UIView's can't.Who can tell me why?
code:
// ViewController.m
[self.view addSubview:self.testLabel];
[self.view addSubview:self.testView];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
self.testLabel.frame = CGRectMake(20, 20, 100, 100);
});
The above code will be detected but the following will not .
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
self.testView.frame = CGRectMake(20, 20, 100, 100);
});
hook code :
#implementation UIView (ThreadSafeGuard)
+ (void)load {
[DBHookUtil swizzlingInClass:[self class] originalSelector:#selector(setNeedsLayout) swizzledSelector:#selector(db_setNeedsLayout)];
[DBHookUtil swizzlingInClass:[self class] originalSelector:#selector(setNeedsDisplay) swizzledSelector:#selector(db_setNeedsDisplay)];
[DBHookUtil swizzlingInClass:[self class] originalSelector:#selector(setNeedsDisplayInRect:) swizzledSelector:#selector(db_setNeedsDisplayInRect:)];
}
- (void)db_setNeedsLayout {
NSAssert([NSThread isMainThread], #"refresh UI on background thread");
[self db_setNeedsLayout];
}
- (void)db_setNeedsDisplay {
NSAssert([NSThread isMainThread], #"refresh UI on background thread");
[self db_setNeedsDisplay];
}
- (void)db_setNeedsDisplayInRect:(CGRect)rect {
NSAssert([NSThread isMainThread], #"refresh UI on background thread");
[self db_setNeedsDisplayInRect:rect];
}
#end
crash log:
2017-05-15 18:17:40.876 ThreadSafeGuardDemo[50800:19659410] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'refresh UI on background thread'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105181b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000104be6141 objc_exception_throw + 48
2 CoreFoundation 0x0000000105185cf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00000001047803b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 ThreadSafeGuardDemo 0x0000000104615068 -[UIView(ThreadSafeGuard) db_setNeedsDisplay] + 264
5 UIKit 0x00000001058311f6 -[UILabel setNeedsDisplay] + 55
6 UIKit 0x00000001058279e6 -[UILabel _invalidateAsNeededForNewSize:oldSize:withLinkCheck:] + 336
7 UIKit 0x0000000105827c9f -[UILabel setFrame:] + 76
8 ThreadSafeGuardDemo 0x0000000104614a76 __29-[ViewController viewDidLoad]_block_invoke + 278
9 libdispatch.dylib 0x0000000107f744a6 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x0000000107f9d05c _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000107f7f198 _dispatch_root_queue_drain + 1358
12 libdispatch.dylib 0x0000000107f7ebef _dispatch_worker_thread3 + 123
13 libsystem_pthread.dylib 0x00000001083c3746 _pthread_wqthread + 1299
14 libsystem_pthread.dylib 0x00000001083c3221 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

When I use a NSMutableArray which as a property of a Singleton , to add some object into the NSMutableArray. It crushed

Here is my sampleCode :
-(IBAction)add:(id)sender {
//ShoppingManager sharedManager is a singleton
[[ShoppingManager sharedManager].onlineClassArray addObject:#(1)];
}
and code in ShoppingManager.m:
//singleton
+ (ShoppingManager *)sharedManager{
static id instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [[self alloc]init];
});
return instance;
}
- (OnlineClassItemizeArray *)onlineClassArray{
if (!_onlineClassArray) {
_onlineClassArray = [OnlineClassItemizeArray array];
}
return _onlineClassArray;
}
and the ShoppingMananger.h:
#interface ShoppingManager : NSObject
#property(nonatomic,strong) OnlineClassItemizeArray * onlineClassArray;
+ (ShoppingManager*)sharedManager;
#end
I don't know what is wrong with these codes.when i added some object into the mutableArray,it stopped at this line:(a all Exception BreakPoint)
_onlineClassArray = [OnlineClassItemizeArray array];
than crushed at here:
DISPATCH_INLINE DISPATCH_ALWAYS_INLINE DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
DISPATCH_SWIFT3_UNAVAILABLE("Use lazily initialized globals instead")
void
_dispatch_once(dispatch_once_t *predicate,
DISPATCH_NOESCAPE dispatch_block_t block)
{
if (DISPATCH_EXPECT(*predicate, ~0l) != ~0l) {
dispatch_once(predicate, block);//<---crushed here
} else {
dispatch_compiler_barrier();
}
DISPATCH_COMPILER_CAN_ASSUME(*predicate == ~0l);
}
and here is the whole error msg:
2017-03-14 01:01:36.586 tesr1111[7075:1333259] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray initWithCapacity:]: method only defined for abstract class. Define -[OnlineClassItemizeArray initWithCapacity:]!'
*** First throw call stack:
(
0 CoreFoundation 0x00000001100c4d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010fb2621e objc_exception_throw + 48
2 CoreFoundation 0x00000001101357df __CFRequireConcreteImplementation + 255
3 CoreFoundation 0x00000001101241a7 -[NSMutableArray initWithCapacity:] + 39
4 tesr1111 0x000000010f54e6d0 -[ShoppingManager init] + 160
5 tesr1111 0x000000010f54e5f1 __32+[ShoppingManager sharedManager]_block_invoke + 65
6 libdispatch.dylib 0x0000000112eda0cd _dispatch_client_callout + 8
7 libdispatch.dylib 0x0000000112ebf1f8 dispatch_once_f + 501
8 tesr1111 0x000000010f54e588 +[ShoppingManager sharedManager] + 136
9 tesr1111 0x000000010f54de9d -[ViewController add:] + 61
10 UIKit 0x00000001104ea8bc -[UIApplication sendAction:to:from:forEvent:] + 83
11 UIKit 0x0000000110670c38 -[UIControl sendAction:to:forEvent:] + 67
12 UIKit 0x0000000110670f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
13 UIKit 0x000000011066fe4d -[UIControl touchesEnded:withEvent:] + 668
14 UIKit 0x0000000110558545 -[UIWindow _sendTouchesForEvent:] + 2747
15 UIKit 0x0000000110559c33 -[UIWindow sendEvent:] + 4011
16 UIKit 0x00000001105069ab -[UIApplication sendEvent:] + 371
17 UIKit 0x0000000120cca481 -[UIApplicationAccessibility sendEvent:] + 93
18 UIKit 0x0000000110cf372d __dispatchPreprocessedEventFromEventQueue + 3248
19 UIKit 0x0000000110cec463 __handleEventQueue + 4879
20 CoreFoundation 0x0000000110069761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000011004e98c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x000000011004de76 __CFRunLoopRun + 918
23 CoreFoundation 0x000000011004d884 CFRunLoopRunSpecific + 420
24 GraphicsServices 0x0000000113eb0a6f GSEventRunModal + 161
25 UIKit 0x00000001104e8c68 UIApplicationMain + 159
26 tesr1111 0x000000010f54e4df main + 111
27 libdyld.dylib 0x0000000112f2668d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
If anyone can give me any idea or helping link. Thanks in advance.
You are subclassing NSMutableArray incorrectly. It is a class cluster and there is a minimum set of methods that need to be implemented.
In this case, you are calling initWithCapacity: but haven't overridden that method. Or, more likely, you are calling a generic method (init) that calls through to that method.
Exactly as the exception says:
2017-03-14 01:01:36.586 tesr1111[7075:1333259] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSMutableArray initWithCapacity:]: method only defined for abstract class. Define -[OnlineClassItemizeArray initWithCapacity:]!'
However, subclassing the collection classes is a code smell. It is pretty much never done. There are rare cases where it makes sense; what is yours?

Calling method is causing Error creating LLDB target

I am trying to make my first Objective-C library. I am creating a method which will take in a UIImage and return NSMutableData. I have created the following:
+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image
{
int maxWidth = 100;
BOOL drawerKick = YES;
BOOL compressionEnable = YES;
RasterDocument *rasterDoc = [[RasterDocument alloc] initWithDefaults:RasSpeed_Medium endOfPageBehaviour:RasPageEndMode_FeedAndFullCut endOfDocumentBahaviour:RasPageEndMode_FeedAndFullCut topMargin:RasTopMargin_Standard pageLength:0 leftMargin:0 rightMargin:0];
StarBitmap *starbitmap = [[StarBitmap alloc] initWithUIImage:image :maxWidth :false];
NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
NSData *shortcommand = [rasterDoc BeginDocumentCommandData];
[commandsToPrint appendData:shortcommand];
shortcommand = [starbitmap getImageDataForPrinting:compressionEnable];
[commandsToPrint appendData:shortcommand];
shortcommand = [rasterDoc EndDocumentCommandData];
[commandsToPrint appendData:shortcommand];
if (drawerKick == YES) {
[commandsToPrint appendBytes:"\x07"
length:sizeof("\x07") - 1]; // KickCashDrawer
}
[starbitmap release];
[rasterDoc release];
return commandsToPrint;
}
Just for testing purposes, I am trying to call it from a button click event:
- (IBAction)DevButton_TouchUpInside:(id)sender {
UIImage *imageToPrint = [UIImage imageNamed:#"image1.png"];
// NSMutableData *commandsToPrint = [[NSMutableData alloc] init];
// *commandsToPrint=[self GetDataToSendToPrinter:imageToPrint];
//This is where I call it
NSMutableData *commandsToPrint = [self GetDataToSendToPrinter:imageToPrint];
int commandSize = (int)[commandsToPrint length];
unsigned char *dataToSentToPrinter = (unsigned char *)malloc(commandSize);
[commandsToPrint getBytes:dataToSentToPrinter];
NSString *portName = #"TCP:10.0.1.4";
NSString *portSettings = #"Standard";
NSMutableString *message;
SMPort *starPort = nil;
starPort = [SMPort getPort:portName :portSettings :10000];
[starPort writePort:dataToSentToPrinter :0 :commandSize];
}
However I keep getting the following crash when clicking on the button:
Warning: Error creating LLDB target at path '/Users/.../Library/Developer/Xcode/DerivedData/IOS_SDK-cjctcqoxudpegpadjbwitveqtkso/Build/Products/Debug-iphonesimulator/StarIO SDK.app'- using an empty LLDB target which can cause slow memory reads from remote devices.
2014-09-26 18:39:22.588 StarIO SDK[17823:513276] -[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260
2014-09-26 18:39:22.624 StarIO SDK[17823:513276] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:]: unrecognized selector sent to instance 0xb366260'
*** First throw call stack:
(
0 CoreFoundation 0x021c4df6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01c49a97 objc_exception_throw + 44
2 CoreFoundation 0x021cca75 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x021159c7 ___forwarding___ + 1047
4 CoreFoundation 0x0211558e _CF_forwarding_prep_0 + 14
5 StarIO SDK 0x000428bb -[IOS_SDKViewControllerRasterMode DevButton_TouchUpInside:] + 107
6 libobjc.A.dylib 0x01c5f7cd -[NSObject performSelector:withObject:withObject:] + 84
7 UIKit 0x0042179d -[UIApplication sendAction:to:from:forEvent:] + 99
8 UIKit 0x0042172f -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
9 UIKit 0x00554a16 -[UIControl sendAction:to:forEvent:] + 69
10 UIKit 0x00554e33 -[UIControl _sendActionsForEvents:withEvent:] + 598
11 UIKit 0x0055409d -[UIControl touchesEnded:withEvent:] + 660
12 UIKit 0x00471aba -[UIWindow _sendTouchesForEvent:] + 874
13 UIKit 0x00472595 -[UIWindow sendEvent:] + 791
14 UIKit 0x00437aa9 -[UIApplication sendEvent:] + 242
15 UIKit 0x004478de _UIApplicationHandleEventFromQueueEvent + 20690
16 UIKit 0x0041c079 _UIApplicationHandleEventQueue + 2206
17 CoreFoundation 0x020e87bf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x020de2cd __CFRunLoopDoSources0 + 253
19 CoreFoundation 0x020dd828 __CFRunLoopRun + 952
20 CoreFoundation 0x020dd1ab CFRunLoopRunSpecific + 443
21 CoreFoundation 0x020dcfdb CFRunLoopRunInMode + 123
22 GraphicsServices 0x03b8c24f GSEventRunModal + 192
23 GraphicsServices 0x03b8c08c GSEventRun + 104
24 UIKit 0x0041fe16 UIApplicationMain + 1526
25 StarIO SDK 0x000027e2 main + 130
26 libdyld.dylib 0x036f0ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I asume I am missing something really basic. It's the first Objective-C method I have created, I'm just looking at building a simple library I can then wrap in a Xamarin binding. Where am I going wrong?
You're calling a class method from an instance method.
+ (NSMutableData *)GetDataToSendToPrinter:(UIImage *)image //Should be called using the class name
- (IBAction)DevButton_TouchUpInside:(id)sender //Should be called using self
I'm not sure how that compiled actually, you should've gotten an error like this:
No visible #interface for IOS_SDKViewControllerRasterMode declares the selector 'GetDataToSendToPrinter:'
Per the log it spit out, it's not finding the function GetDataToSendToPrinter:. Try calling it as a class method:
NSMutableData *commandsToPrint = [IOS_SDKViewControllerRasterMode GetDataToSendToPrinter:imageToPrint];

Resources