How to fix the crash in CFNotificationCenterAddObserver for NSWorkspaceDidActivateApplicationNotification? - c++

Not very much accustom to Objective C, hence trying to observe NSWorkspaceDidActivateApplicationNotification event in C++ code with CFNotificationCenterAddObserver() method.
#include<CoreFoundation/CFNotificationCenter.h>
#include<iostream>
#include<QGuiApplication>
void Callback (CFNotificationCenterRef center, void* observer, CFNotificationName name,
const void* object,
CFDictionaryRef userInfo)
{
std::cout << "Hello World\n";
//NSLog(#"New application: %#", [[name userInfo] objectForKey:NSWorkspaceApplicationKey]);
}
int main (int argc, char** argv)
{
QGuiApplication application(argc, argv);
std::cout << "Add observer\n";
CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), nullptr, Callback,
CFStringRef("NSWorkspaceDidActivateApplicationNotification"), nullptr,
CFNotificationSuspensionBehaviorDeliverImmediately);
std::cout << "Added ...\n";
return application.exec();
}
However it results in below crash. If I try to run in debug mode, then it sometimes shows the below crash or sometimes get stuck in that function itself.
Add observer
2021-12-03 21:44:24.527086+0530 Test[17288:982994] -[__NSTaggedDate length]: unrecognized selector sent to instance 0x100007c65
2021-12-03 21:44:24.527916+0530 Test[17288:982994] [General] An uncaught exception was raised
2021-12-03 21:44:24.527943+0530 Test[17288:982994] [General] -[__NSTaggedDate length]: unrecognized selector sent to instance 0x100007c65
2021-12-03 21:44:24.528044+0530 Test[17288:982994] [General] (
0 CoreFoundation 0x00007fff35570035 __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff5fc80a17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff355e9fce -[NSObject(NSObject) __retain_OA] + 0
3 CoreFoundation 0x00007fff35511e9f ___forwarding___ + 1485
4 CoreFoundation 0x00007fff35511848 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x00007fff355aca4c __CFXNotificationRegisterObserver + 588
6 CoreFoundation 0x00007fff3548a037 CFNotificationCenterAddObserver + 204
7 Test 0x00000001000066a1 main + 129
8 libdyld.dylib 0x00007fff614503d5 start + 1
)
2021-12-03 21:44:24.528241+0530 Test[17288:982994] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSTaggedDate length]: unrecognized selector sent to instance 0x100007c65'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff35570035 __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff5fc80a17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff355e9fce -[NSObject(NSObject) __retain_OA] + 0
3 CoreFoundation 0x00007fff35511e9f ___forwarding___ + 1485
4 CoreFoundation 0x00007fff35511848 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x00007fff355aca4c __CFXNotificationRegisterObserver + 588
6 CoreFoundation 0x00007fff3548a037 CFNotificationCenterAddObserver + 204
7 Test 0x00000001000066a1 main + 129
8 libdyld.dylib 0x00007fff614503d5 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
How to fix this?

Use CFSTR macro to create a CFStringRef from a constant C string like so:
CFSTR("NSWorkspaceDidActivateApplicationNotification")
NSWorkspaceDidActivateApplicationNotification docs says that you have to use NSWorkspace.notificationCenter to receive it, CFNotificationCenterGetDistributedCenter won't work.

Related

MAC audioUnit AudioComponentInstanceDispose crash

the audio unit subType is kAudioUnitSubType_VoiceProcessingIO,
and use kAudioOutputUnitProperty_CurrentDevice to set Device ID for the audio unit
OSStatus result = AudioOutputUnitStop(audio_unit);
result = AudioUnitUninitialize(audio_unit);
result = AudioComponentInstanceDispose(audio_unit);
Thread trace:
3 ExceptionHandling 0x00007fff3c64ef31 -[NSExceptionHandler _handleException:mask:] + 364
4 ExceptionHandling 0x00007fff3c64ecac NSExceptionHandlerUncaughtSignalHandler + 35
5 libsystem_platform.dylib 0x00007fff204d3d7d _sigtramp + 29
6 CoreFoundation 0x00007fff2050f381 CFStringGetLength + 11
7 CoreFoundation 0x00007fff205225c7 CFStringCompare + 24
8 CoreAudio 0x00007fff221e83f5 _ZN9HALDevice4DuckEfPK14AudioTimeStampf + 921
9 CoreAudio 0x00007fff21d3ed48 AudioDeviceDuck + 843
10 AudioDSP 0x00000001390d7d4a _Z14DuckOtherAudiojff + 51
11 AudioDSP 0x0000000139213e06 _ZN16AUVoiceProcessor22DestroyAggregateDeviceEv + 974
12 AudioDSP 0x0000000139215459 _ZN16AUVoiceProcessorD2Ev + 417
13 AudioDSP 0x00000001392efdec _ZN13ComponentBase8AP_CloseEPv + 30
14 AudioToolboxCore 0x00007fff219e4b6a AudioComponentInstanceDispose + 55
You are disposing of an Audio Instance before it is stopped.
Note that AudioOutputUnitStop may not stop an audio unit immediately, since the audio thread runs asynchronously. If you delay for a half second after stopping the audio unit, that other thread is likely stopped by then and then you can more safely dispose of its resources.

Crash reported generated by Compiler in Swift 5 xcode 11

My app has been rejected from Apple quite a long time now.
They say that I get crash on dashboard but although it works fine on simulator and device
I implemented 2 approaches to get the crash report
Firebase Analytics
Symbolised the crash reported shared by Apple.
.init(coder:)
It says error generated by compiler
8 SSBS 0x10521c174 DashboardViewController.init(coder:) + 5308788 (<compiler-generated>:0)
9 SSBS 0x10521c238 #objc DashboardViewController.init(coder:) + 5308984 (<compiler-generated>:0)
In this case, what do I need to implement in my ViewController Class file
So the crash report generated fr
om that is :
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
*Last Exception Backtrace:
0 CoreFoundation 0x1adc3b794 0x1adb11000 + 1222548
1 libobjc.A.dylib 0x1ad95dbcc 0x1ad958000 + 23500
2 CoreFoundation 0x1adb31b98 0x1adb11000 + 134040
3 UIKitCore 0x1b1652c74 0x1b12b4000 + 3796084
4 UIFoundation 0x1b123fe94 0x1b11d5000 + 437908
5 UIFoundation 0x1b12400b4 0x1b11d5000 + 438452
6 UIFoundation 0x1b11dccac 0x1b11d5000 + 31916
7 UIKitCore 0x1b1699dd0 0x1b12b4000 + 4087248
8 SSBS 0x10521c174 DashboardViewController.init(coder:) + 5308788 (<compiler-generated>:0)
9 SSBS 0x10521c238 #objc DashboardViewController.init(coder:) + 5308984 (<compiler-generated>:0)
10 UIKitCore 0x1b1973c40 0x1b12b4000 + 7076928
11 UIFoundation 0x1b123fe94 0x1b11d5000 + 437908
12 UIFoundation 0x1b11dccac 0x1b11d5000 + 31916
13 UIKitCore 0x1b1977bbc 0x1b12b4000 + 7093180
14 UIFoundation 0x1b123fe94 0x1b11d5000 + 437908
15 UIFoundation 0x1b12400b4 0x1b11d5000 + 438452
16 UIFoundation 0x1b11dccac 0x1b11d5000 + 31916
17 UIKitCore 0x1b1972cd8 0x1b12b4000 + 7072984
18 UIKitCore 0x1b1975858 0x1b12b4000 + 7084120
19 UIKitCore 0x1b1e4784c 0x1b12b4000 + 12138572
20 SSBS 0x1052b55a8 closure #1 in LoginViewController.RegisterUserOnServer() + 5936552 (LoginViewController.swift:707)
21 Alamofire 0x105e47454 0x105d54000 + 996436
22 Alamofire 0x105d7ac94 0x105d54000 + 158868
23 libdispatch.dylib 0x1ad9009a8 0x1ad8a6000 + 371112
24 libdispatch.dylib 0x1ad901524 0x1ad8a6000 + 374052
25 libdispatch.dylib 0x1ad8b35b4 0x1ad8a6000 + 54708
26 CoreFoundation 0x1adbb97fc 0x1adb11000 + 690172
27 CoreFoundation 0x1adbb46d0 0x1adb11000 + 669392
28 CoreFoundation 0x1adbb3ce8 0x1adb11000 + 666856
29 GraphicsServices 0x1b7cfe38c 0x1b7cfb000 + 13196
30 UIKitCore 0x1b1ce2444 0x1b12b4000 + 10675268
31 SSBS 0x1051ba4b4 main + 4908212 (AppDelegate.swift:21)
32 libdyld.dylib 0x1ada3b8f0 0x1ada3a000 + 6384
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001ada30d88 0x1ada0b000 + 155016
1 libsystem_pthread.dylib 0x00000001ad9491e8 0x1ad947000 + 8680
2 libsystem_c.dylib 0x00000001ad89c9b0 0x1ad82a000 + 469424
3 libsystem_c.dylib 0x00000001ad89c940 0x1ad82a000 + 469312
4 libc++abi.dylib 0x00000001ada04cc0 0x1ad9f2000 + 76992
5 libc++abi.dylib 0x00000001ad9f6e10 0x1ad9f2000 + 19984
6 libobjc.A.dylib 0x00000001ad95de80 0x1ad958000 + 24192
7 SSBS 0x0000000105501948 FIRCLSTerminateHandler() + 8345928 (FIRCLSException.mm:338)
8 SSBS 0x00000001054abc90 CLSTerminateHandler+ 7994512 () + 348
9 libc++abi.dylib 0x00000001ada0414c 0x1ad9f2000 + 74060
10 libc++abi.dylib 0x00000001ada040e4 0x1ad9f2000 + 73956
11 libdispatch.dylib 0x00000001ad901538 0x1ad8a6000 + 374072
12 libdispatch.dylib 0x00000001ad8b35b4 0x1ad8a6000 + 54708
13 CoreFoundation 0x00000001adbb97fc 0x1adb11000 + 690172
14 CoreFoundation 0x00000001adbb46d0 0x1adb11000 + 669392
15 CoreFoundation 0x00000001adbb3ce8 0x1adb11000 + 666856
16 GraphicsServices 0x00000001b7cfe38c 0x1b7cfb000 + 13196
17 UIKitCore 0x00000001b1ce2444 0x1b12b4000 + 10675268
18 SSBS 0x00000001051ba4b4 main + 4908212 (AppDelegate.swift:21)
19 libdyld.dylib 0x00000001ada3b8f0 0x1ada3a000 + 6384*
code of DashboardViewController:
class DashboardViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//navigationHeaderItem()
// Do any additional setup after loading the view.
if(self.isNewDashboard == nil || self.isNewDashboard == true){
self.newDashboardView.isHidden = false
}else{
self.newDashboardView.isHidden = true
}
let menuMangerObj = MenuDrawerManager()
let resultItem=menuMangerObj.getByItemDrawerItem("My Meetings") as NSArray
if(resultItem.count>0){
self.newDashboardView.isHidden = false
}else{
self.newDashboardView.isHidden = true
}
self.loginUserName.text=userdDefaultData.string(forKey: "loginUserName")
}
}
I initiate a view controller like:
let vcObj = self.storyboard?.instantiateViewController(withIdentifier: "DashboardController") as! DashboardViewController
vcObj.isNewDashboard = true
self.navigationController?.pushViewController(vcObj, animated: true)
Am I am missing anything here?

opencv c++ VideoCapture open() error

I'm trying to read a webcam stream in opencv c++ on OS X but when I attempt to open the feed I produce the following error:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
Stacktrace:
*** First throw call stack:
(
0 CoreFoundation 0x00007fff86cfee7b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff9b8e8cad objc_exception_throw + 48
2 CoreFoundation 0x00007fff86c181dc -[__NSArrayM objectAtIndex:] + 204
3 libopencv_highgui.2.4.dylib 0x0000000104b09280 _ZN13CvCaptureFileC2EPKc + 350
4 libopencv_highgui.2.4.dylib 0x0000000104b07cf2 _Z32cvCreateFileCapture_AVFoundationPKc + 34
5 libopencv_highgui.2.4.dylib 0x0000000104afb7ee cvCreateFileCapture + 14
6 libopencv_highgui.2.4.dylib 0x0000000104afba9e _ZN2cv12VideoCapture4openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 64
7 classification.bin 0x0000000104031842 main + 370
8 libdyld.dylib 0x00007fff9c1cc255 start + 1
9 ??? 0x0000000000000005 0x0 + 5
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
Code:
VideoCapture cap;
printf("vidcap created\n"); // This message is printed
cap.open("http://192.168.1.155:80/video.cgi?dummy=.mjpg");
printf("feed opened\n"); // this one is not
What could be the reason for this error?

Crash on devices running iOS 8.4

Can anyone help here please?
I submitted version 2 of my app only to have it rejected as it crashed on a number of devices running 8.4 ….
{"bundleID":"properties.axxxxxxx.xxxxxxxxx”,”app_name”:”My App”,”share_with_app_devs":false,"name”:”My App”,”app_version":"2.0","is_first_party":false,"os_version":"iPhone OS 8.4 (12H143)","bug_type":"109","slice_uuid":"c94c9011-955b-3d2c-b949- 5797aefef990","build_version":"2.2","adam_id":0}
Incident Identifier: A3B5332C-0A28-4E48-BFEE-F1FB95495715
CrashReporter Key: 09b24a3f5088bdc521191691c1969f4d0b4b4f7a
Hardware Model: iPhone5,3
Process: My App [1147]
Path: /private/var/mobile/Containers/Bundle/Application/6E6E3FFA-11CD-4DA0-995D-D46C8E2C9624/My App.app/My App
Identifier: properties.axxxxxxx.xxxxxxxx
Version: 2.2 (2.0)
Code Type: ARM (Native)
Parent Process: launchd.development [1]
Date/Time: 2015-09-20 01:23:11.929 -0700
Launch Time: 2015-09-20 01:23:11.557 -0700
OS Version: iOS 8.4 (12H143)
UDID: b01ae3fde269ba2ac345c6dae55c505ad34d45ae
Report Version: 105
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 0
Filtered syslog:
2015-09-20 01:23:11.684 Alien Rabbits[1147]: <Error> assertion failed: 12H143: libxpc.dylib + 51915 [88A50DD0-8E7B-3CD6-AC30-BA113A415E4F]: 0x7d
2015-09-20 01:23:11.885 Alien Rabbits[1147]: <Error> +[NSMutableArray newMutableArrayUsingWeakReferencesWithCapacity:]: unrecognized selector sent to class 0x31e2aaf4
2015-09-20 01:23:11.888 Alien Rabbits[1147]: <Error> *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSMutableArray newMutableArrayUsingWeakReferencesWithCapacity:]: unrecognized selector sent to class 0x31e2aaf4'
*** First throw call stack:
(0x22a86fef 0x314a2c8b 0x22a8c325 0x22a8a327 0x229b9e78 0x610f5 0xb0507 0x91771 0x9116b 0xa3599 0x2b023 0x2616f243 0x26365ad9 0x26368199 0x26372e19 0x2636693b 0x2973eec9 0x22a4cfd5 0x22a4c299 0x22a4add3 0x22997201 0x22997013 0x26168e17 0x26163a09 0x2aecb 0x31a54aaf)
Last Exception Backtrace:
(0x22a86fea 0x314a2c86 0x22a8c320 0x22a8a322 0x229b9e74 0x610f0 0xb0502 0x9176c 0x91166 0xa3594 0x2b01e 0x2616f23e 0x26365ad4 0x26368194 0x26372e14 0x26366936 0x2973eec4 0x22a4cfd0 0x22a4c294 0x22a4adce 0x229971fc 0x2299700e 0x26168e12 0x26163a04 0x2aec6 0x31a54aaa)
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x31b1edf0 0x31b0a000 + 85488
1 libsystem_pthread.dylib 0x31b9dcc2 0x31b9a000 + 15554
2 libsystem_c.dylib 0x31aba904 0x31a70000 + 305412
3 libc++abi.dylib 0x30dc29c4 0x30dc2000 + 2500
4 libc++abi.dylib 0x30ddc66c 0x30dc2000 + 108140
5 libobjc.A.dylib 0x314a2f22 0x3149c000 + 28450
6 libc++abi.dylib 0x30dd9de0 0x30dc2000 + 97760
7 libc++abi.dylib 0x30dd98aa 0x30dc2000 + 96426
8 libobjc.A.dylib 0x314a2dce 0x3149c000 + 28110
9 CoreFoundation 0x22997298 0x2297f000 + 98968
10 CoreFoundation 0x2299700e 0x2297f000 + 98318
11 UIKit 0x26168e12 0x260f4000 + 478738
12 UIKit 0x26163a04 0x260f4000 + 457220
13 My App 0x0002aec6 0x23000 + 32454
14 libdyld.dylib 0x31a54aac 0x31a53000 + 6828
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x31b0b224 0x31b0a000 + 4644
1 libdispatch.dylib 0x31a400ec 0x31a32000 + 57580
2 libdispatch.dylib 0x31a34d36 0x31a32000 + 11574
Thread 2 name: Dispatch queue: FBSSerialQueue
Thread 2:
0 libsystem_kernel.dylib 0x31b0b4c4 0x31b0a000 + 5316
1 libdispatch.dylib 0x31a3e5da 0x31a32000 + 50650
2 FrontBoardServices 0x2973eea6 0x29729000 + 89766
3 libdispatch.dylib 0x31a332e0 0x31a32000 + 4832
4 libdispatch.dylib 0x31a3b724 0x31a32000 + 38692
5 libdispatch.dylib 0x31a35aa8 0x31a32000 + 15016
6 libdispatch.dylib 0x31a3cf9c 0x31a32000 + 44956
7 libdispatch.dylib 0x31a3e3be 0x31a32000 + 50110
8 libsystem_pthread.dylib 0x31b9adbe 0x31b9a000 + 3518
9 libsystem_pthread.dylib 0x31b9ab10 0x31b9a000 + 2832
Thread 3:
0 libsystem_kernel.dylib 0x31b1f9c0 0x31b0a000 + 88512
1 libsystem_pthread.dylib 0x31b9ae38 0x31b9a000 + 3640
2 libsystem_pthread.dylib 0x31b9ab10 0x31b9a000 + 2832
Thread 4:
0 libsystem_kernel.dylib 0x31b1f9c0 0x31b0a000 + 88512
1 libsystem_pthread.dylib 0x31b9ae38 0x31b9a000 + 3640
2 libsystem_pthread.dylib 0x31b9ab10 0x31b9a000 + 2832
Thread 5:
0 libsystem_kernel.dylib 0x31b1f9c0 0x31b0a000 + 88512
1 libsystem_pthread.dylib 0x31b9ae38 0x31b9a000 + 3640
2 libsystem_pthread.dylib 0x31b9ab10 0x31b9a000 + 2832
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00000000 r1: 0x00000000 r2: 0x00000000 r3: 0x00000003
r4: 0x00000006 r5: 0x344be9dc r6: 0x344aa840 r7: 0x003233c8
r8: 0x16e86fe0 r9: 0x00000000 r10: 0x344a9074 r11: 0x16e87004
ip: 0x00000148 sp: 0x003233bc lr: 0x31b9dcc7 pc: 0x31b1edf0
cpsr: 0x00080010
No problems for me when running the app on an iPhone 6 with 8.4 and on a variety of devices running 8.0
The only way I have found to replicate the crash is running a device iPhone 4s on 8.0 using the profile tool and then I get:
2015-09-27 17:54:47.434 My App[9161:1516779] +[NSMutableArray newMutableArrayUsingWeakReferencesWithCapacity:]: unrecognized selector sent to class 0x393e5960
2015-09-27 17:54:47.444 My APP[9161:1516779] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSMutableArray newMutableArrayUsingWeakReferencesWithCapacity:]: unrecognized selector sent to class 0x393e5960'
*** First throw call stack:
(0x2b20a5f7 0x38a7cc77 0x2b20f9d9 0x2b20d999 0x2b13eb88 0xc4501 0x11383b 0xf4a71 0xf4463 0x1068a9 0x8e523 0x2e719469 0x2e90e515 0x2e910a49 0x2e91b2f9 0x2e90f2eb 0x319800c9 0x2b1d0ffd 0x2b1d02c1 0x2b1cee1b 0x2b11bb31 0x2b11b943 0x2e713127 0x2e70df21 0x8e3cb 0x39018aaf)
libc++abi.dylib:
terminating with uncaught exception of type NSException
The app will run on that device if the profile tool is not used. When it is loaded with the profile tool it will crashes when phone is disconnected connected.
The app is crashing before its finished launching from:
-(BOOL) application: (UIApplication*) application didFinishLaunchingWithOptions: (NSDictionary*) launchOptions
and it’s the call to Initialise OpenAL:
[OALSimpleAudio sharedInstance];
in the cocos2d CCAppDelegate.m file that triggers the crash.
If I take this call out, the crash happens a second or so later and the profile tool gives;
2015-09-27 18:38:52.634 My App[9188:1523335] -[EAGLContext ensureCurrentContext]: unrecognized selector sent to instance 0x167918e0
2015-09-27 18:38:52.667 My App[9188:1523335] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[EAGLContext ensureCurrentContext]: unrecognized selector sent to instance 0x167918e0'
*** First throw call stack:
(0x2b20a5f7 0x38a7cc77 0x2b20fabd 0x2b20d999 0x2b13eb88 0x199c65 0x191f6d 0x19a063 0x19487f 0x10b4ad 0x10aa33 0x10a9fd 0x10aa75 0x1226f1 0x12341b 0x123225 0x1224e5 0x121b63 0x122a1d 0x7d5c9 0xf4ffd 0xa34b9 0xd799f 0x2e6ac19f 0x2e0d7f65 0x2e0d3951 0x2e0d37d9 0x2e0d31c7 0x2e0d2fd1 0x2e91011d 0x2e910eb5 0x2e91b2f9 0x2e90f2eb 0x319800c9 0x2b1d0ffd 0x2b1d02c1 0x2b1cea5f 0x2b11bb31 0x2b11b943 0x2e713127 0x2e70df21 0x7d3fb 0x39018aaf)
libc++abi.dylib:
terminating with uncaught exception of type NSException
I’m using:
xcode 6.2
compiling to 8.0
cocos2d 3.2.1
Hours spent so far trying to resolve this.
Thanks

Bool method to check user input

Hi everybody i am trying to make a boolean method that will return value depending upon the user input for the field when submit button is clicked.
- (BOOL)checkuser:(NSString*)input
{
bool result = NO;
if ([input isEqualToString:#"test"])
{
result = YES;
}
else
{
result = NO;
}
return result;
}
And i am refrencing this method from my program as
else if ([Username checkuser] == YES)
{ // do something
}
with following warning
'NSString' may not respond to '-checkuser'
and i am not getting why my program crashing at this point with following error.
2011-03-22 22:57:25.942 Assignment 2[824:207] -[NSCFString checkuser]: unrecognized selector sent to instance 0x4b7c050
2011-03-22 22:57:25.944 Assignment 2[824:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString checkuser]: unrecognized selector sent to instance 0x4b7c050'
* Call stack at first throw:
(
0 CoreFoundation 0x00db8be9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f0d5c2 objc_exception_throw + 47
2 CoreFoundation 0x00dba6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d2a366 __forwarding + 966
4 CoreFoundation 0x00d29f22 _CF_forwarding_prep_0 + 50
5 Assignment 2 0x00002958 -[Assignment_2ViewController SubmitbuttonPressed:] + 727
6 UIKit 0x002c1a6e -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x003501b5 -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x00352647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
9 UIKit 0x003511f4 -[UIControl touchesEnded:withEvent:] + 458
10 UIKit 0x002e60d1 -[UIWindow _sendTouchesForEvent:] + 567
11 UIKit 0x002c737a -[UIApplication sendEvent:] + 447
12 UIKit 0x002cc732 _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x016eea36 PurpleEventCallback + 1550
14 CoreFoundation 0x00d9a064 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52
15 CoreFoundation 0x00cfa6f7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00cf7983 __CFRunLoopRun + 979
17 CoreFoundation 0x00cf7240 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00cf7161 CFRunLoopRunInMode + 97
19 GraphicsServices 0x016ed268 GSEventRunModal + 217
20 GraphicsServices 0x016ed32d GSEventRun + 115
21 UIKit 0x002d042e UIApplicationMain + 1160
22 Assignment 2 0x00001c04 main + 102
23 Assignment 2 0x00001b95 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
(gdb)
You're over-complicating a very simple problem:
- (BOOL) checkuser:(NSString*)input {
return [input isEqualToString:#"test"];
}
and then to call it:
if ([Username checkUser:#"DONT FORGET YOUR PARAM HERE"]) {
// Do something...
}
In your example, you're not passing any parameter to your method... That's a misstake hence your error.
Also, if you create a method returning a 'BOOL', make sure you're returning a 'BOOL' and not a 'bool'. You have to always keep in mind that the underlying types can be different, even if a bool can be evaluated to a BOOL.
else if ([Username checkuser] == YES)
checkuser is supposed to receive a NSString*, which you are not sending though and is the reason for error messages. So, it should be -
Assuming someNSString is initialized and is of type NSString*.
else if( ([Username checkuser:someNSString] ) == YES )
// ^^^^^^^^^^^^ Needs to be passed as the method prototype mentions so.
{
// ....
}
NSString* someNSString = #"Forgot to pass this" ;
else if( ([Username checkuser:someNSString] ) == YES )
// ^^^^^^^^^^^^ Needs to be passed as the method prototype mentions so.
{
// ....
}