iOS 9 Local Notifications using Swift 2 - ios

I have the following code
#IBAction func triggerNotif(sender: UIButton) {
let dateComp:NSDateComponents = NSDateComponents()
dateComp.year = 2015
dateComp.month = 11
dateComp.day = 12
dateComp.hour = 21
dateComp.minute = 30
dateComp.timeZone = NSTimeZone.systemTimeZone()
let calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
let date:NSDate = calender.dateFromComponents(dateComp)!
let notification:UILocalNotification = UILocalNotification()
notification.alertBody = "body of notification"
notification.fireDate = date
notification.repeatInterval = NSCalendarUnit.Day
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
Basically, I'm trying to trigger a notification that repeats every day using a UIButton. I referred to many other questions on this site to form up this code, and it builds successfully.
But when I click the button, I'm faced with this:
2015-11-12 18:30:17.025 Application Name[95723:485982] -[Application_Name.SettingsViewController triggerNotifBtn:]: unrecognized selector sent to instance 0x7f9163727d70
2015-11-12 18:30:17.035 Application Name[95723:485982] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Application_Name.SettingsViewController triggerNotifBtn:]: unrecognized selector sent to instance 0x7f9163727d70'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d293f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010efb7deb objc_exception_throw + 48
2 CoreFoundation 0x000000010d29c56d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010d1e9eea ___forwarding___ + 970
4 CoreFoundation 0x000000010d1e9a98 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010dab1e91 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x000000010dc1d4d8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010dc1d7a4 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x000000010dc1c8d4 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x000000010db1fed1 -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x000000010db20c06 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010dad02fa -[UIApplication sendEvent:] + 263
12 UIKit 0x000000010daaaabf _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x000000010d1c0011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x000000010d1b5f3c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x000000010d1b53f3 __CFRunLoopRun + 867
16 CoreFoundation 0x000000010d1b4e08 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x0000000111887ad2 GSEventRunModal + 161
18 UIKit 0x000000010dab030d UIApplicationMain + 171
19 Application Name 0x000000010d0a8b6d main + 109
20 libdyld.dylib 0x000000010fabf92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
What's wrong?

you set triggerNotifBtn as function name but your function name is triggerNotif

Related

Swift: Not able to navigate to another view controller

I really do not know what mistake am I doing in the following lines:
// Instantiate SecondViewController
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "RegistrationScreen2View") as! RegistrationScreen2ViewController
self.navigationController?.pushViewController(secondViewController, animated: true)
I am not able to move to second view controller in the story board I have mentioned story board id as RegistrationScreen2View for RegistrationScreen2ViewController.
I am getting the following exception:
2016-10-24 11:26:16.607 toadways[965:11142] -[toadways.RegistrationScreen1ViewController continue]: unrecognized selector sent to instance 0x7fe05dc34ec0
2016-10-24 11:26:16.619 toadways[965:11142] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[toadways.RegistrationScreen1ViewController continue]: unrecognized selector sent to instance 0x7fe05dc34ec0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010efa534b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ea0621e objc_exception_throw + 48
2 CoreFoundation 0x000000010f014f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010ef2ac15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010ef2a798 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010f3cab88 -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x000000010f5502b2 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010f5505cb -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x000000010f54f4c7 -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x000000010f4380d5 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x000000010f4397c3 -[UIWindow sendEvent:] + 4011
11 UIKit 0x000000010f3e6a33 -[UIApplication sendEvent:] + 371
12 UIKit 0x000000010fbd8b6d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x000000010fbd1817 __handleEventQueue + 4879
14 CoreFoundation 0x000000010ef4a311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010ef2f59c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x000000010ef2ea86 __CFRunLoopRun + 918
17 CoreFoundation 0x000000010ef2e494 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x0000000116c0ca6f GSEventRunModal + 161
19 UIKit 0x000000010f3c8f34 UIApplicationMain + 159
20 toadways 0x000000010e2318bf main + 111
21 libdyld.dylib 0x000000011266368d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Please let me know what mistake am I doing.
Your code should work. The most possibility is that you forgot to input an Storyboard ID for your destination ViewController.
***How to Fix:
In the Identity Inspector of destination ViewController, enter its ID.

Sharing using Facebook dialog

let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "https://www.google.com")
content.contentTitle = "ContentTitle"
content.contentDescription = "ContentDescription"
let shareDialog = FBSDKShareDialog();
shareDialog.mode = .Browser
shareDialog.shareContent = content
shareDialog.show()
This is the code I used to share.
While sharing i getting the crash like below
'NSInvalidArgumentException', reason: '-[FBSDKApplicationDelegate openBridgeAPIRequest:useSafariViewController:fromViewController:completionBlock:]: unrecognized selector sent to instance 0x7fa69031c9d0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c2f1e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010bcd8deb objc_exception_throw + 48
2 CoreFoundation 0x000000010c2fa48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010c24790a ___forwarding___ + 970
4 CoreFoundation 0x000000010c2474b8 _CF_forwarding_prep_0 + 120
5 Store 0x000000010a42a858 -[FBSDKShareDialog _showBrowser:] + 417
6 Store 0x000000010a4297c8 -[FBSDKShareDialog show] + 327
7 Store 0x000000010a351d47 _TFC5Store25StorePlayerViewController17didTapShareButtonfS0_FSiT_ + 1847
8 Store 0x000000010a351e6a _TToFC5Store25StorePlayerViewController17didTapShareButtonfS0_FSiT_ + 42
9 Store 0x000000010a35acb0 _TTDFC5Store25StorePlayerViewController17didTapShareButtonfS0_FSiT_ + 48
10 Store 0x000000010a35231d _TTWC5Store25StorePlayerViewControllerS_31DopeMeterViewControllerDelegateS_FS1_17didTapShareButtonuRq_S1__fq_FSiT_ + 45
11 Store 0x000000010a3e24c9 _TFC5Store23DopeMeterViewController12OnShareClickfS0_FCSo8UIButtonT_ + 201
12 Store 0x000000010a3e254a _TToFC5Store23DopeMeterViewController12OnShareClickfS0_FCSo8UIButtonT_ + 58
13 UIKit 0x000000010c6a1194 -[UIApplication sendAction:to:from:forEvent:] + 92
14 UIKit 0x000000010c8106fc -[UIControl sendAction:to:forEvent:] + 67
15 UIKit 0x000000010c8109c8 -[UIControl _sendActionsForEvents:withEvent:] + 311
16 UIKit 0x000000010c80faf8 -[UIControl touchesEnded:withEvent:] + 601
17 UIKit 0x000000010c71049b -[UIWindow _sendTouchesForEvent:] + 835
18 UIKit 0x000000010c7111d0 -[UIWindow sendEvent:] + 865
19 UIKit 0x000000010c6bfb66 -[UIApplication sendEvent:] + 263
20 UIKit 0x000000010c699d97 _UIApplicationHandleEventQueue + 6844
21 CoreFoundation 0x000000010c21da31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010c21395c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x000000010c212e13 __CFRunLoopRun + 867
24 CoreFoundation 0x000000010c212828 CFRunLoopRunSpecific + 488
25 GraphicsServices 0x000000010f640ad2 GSEventRunModal + 161
26 UIKit 0x000000010c69f610 UIApplicationMain + 171
27 doopaadoo 0x00000001090a019d main + 109
28 libdyld.dylib 0x0000000112cb192d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I search lot bt cant find any solution.

segmented control - unrecognized selector sent to instance

I want to use sender to get the value from segmented control, but I am getting the unrecognized selector sent to instance error. The segmented control was added within a view. I've tried removing the semicolon and/or sender and none of the prior posts I've found seem to help. Any ideas?
Swift Code
var segCntrl = UISegmentedControl(items: ["Yes","No"])
segCntrl.tag = 100
segCntrl.center = CGPointMake(qView.bounds.width/2, qView.bounds.minY+40)
self.qView.addSubview(segCntrl)
func segmentorSwitch(sender: AnyObject) {
if(sender.selectedSegmentIndex == 1) {
println("Yes selected")
}
else if(sender.selectedSegmentIndex == 2) {
println("No selected")
}
}
segCntrl.addTarget(self, action: "segmentorSwitch:", forControlEvents: UIControlEvents.ValueChanged)
Error code:
2015-07-07 11:46:24.482 myApp [75641:1855377] -[[myApp.SegViewControllerr segmentorSwitch:]: unrecognized selector sent to instance 0x7fbb0a43b450
2015-07-07 11:46:24.489 myApp[75641:1855377] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[myApp.SegViewController segmentorSwitch:]: unrecognized selector sent to instance 0x7fbb0a43b450'
* First throw call stack:
(
0 CoreFoundation 0x00000001060dcc65 exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010838abb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001060e40ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010603a13c ___forwarding_ + 988
4 CoreFoundation 0x0000000106039cd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001070bfd62 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x00000001071d150a -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010724dfba -[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 570
8 UIKit 0x000000010724ffbf -[UISegmentedControl touchesEnded:withEvent:] + 143
9 UIKit 0x000000010710c958 -[UIWindow _sendTouchesForEvent:] + 735
10 UIKit 0x000000010710d282 -[UIWindow sendEvent:] + 682
11 UIKit 0x00000001070d3541 -[UIApplication sendEvent:] + 246
12 UIKit 0x00000001070e0cdc _UIApplicationHandleEventFromQueueEvent + 18265
13 UIKit 0x00000001070bb59c _UIApplicationHandleEventQueue + 2066
14 CoreFoundation 0x0000000106010431 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
15 CoreFoundation 0x00000001060062fd __CFRunLoopDoSources0 + 269
16 CoreFoundation 0x0000000106005934 __CFRunLoopRun + 868
17 CoreFoundation 0x0000000106005366 CFRunLoopRunSpecific + 470
18 GraphicsServices 0x000000010cc5ba3e GSEventRunModal + 161
19 UIKit 0x00000001070be8c0 UIApplicationMain + 1282
20 myApp 0x0000000104d9a0c7 main + 135
21 libdyld.dylib 0x0000000109458145 start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Looks like segmentorSwitch: is implemented inside another method. Define it outside the method in which your code is contained, and this should be fixed.

Function for UIBarButtonItem

I'm using Core Data and I'm making a save button with this code:
self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: Selector("saveTapped")), animated: true)
The save function:
func saveTapped(){
if (cell!.textField.text.isEmpty) {
let alert = UIAlertView()
alert.title = "Nevyplnené údaje"
alert.message = "Musíš vyplniť všetky údaje o knihe."
alert.addButtonWithTitle("Ok")
alert.show()
}
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let obsah: NSManagedObjectContext = appDel.managedObjectContext!
let entity = NSEntityDescription.entityForName("List", inManagedObjectContext: obsah)
var pridat = Model(entity: entity! , insertIntoManagedObjectContext: obsah)
pridat.kniha = cell!.textField.text
pridat.autor = cell!.textField.text
pridat.rok = cell!.textField.text
pridat.vydavatelstvo = cell!.textField.text
pridat.strany = cell!.textField.text
obsah.save(nil)
}
This is the error I'm getting:
2015-04-29 19:12:42.762 iKnižnica[25716:11689183]
-[iKniz_nica.PridatViewController saveTapped]: unrecognized selector sent to instance 0x7ff5ab63ff50 2015-04-29 19:12:42.851
iKnižnica[25716:11689183] * Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason:
'-[iKniz_nica.PridatViewController saveTapped]: unrecognized selector
sent to instance 0x7ff5ab63ff50'
* First throw call stack: ( 0 CoreFoundation 0x0000000100bccc65 exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000102737bb7 objc_exception_throw + 45 2 CoreFoundation
0x0000000100bd40ad -[NSObject(NSObject) doesNotRecognizeSelector:] +
205 3 CoreFoundation 0x0000000100b2a13c
___forwarding_ + 988 4 CoreFoundation 0x0000000100b29cd8 _CF_forwarding_prep_0 + 120 5 UIKit
0x000000010146cda2 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010146cda2
-[UIApplication sendAction:to:from:forEvent:] + 75 7 UIKit 0x000000010157e54a -[UIControl _sendActionsForEvents:withEvent:] + 467
8 UIKit 0x000000010157d919
-[UIControl touchesEnded:withEvent:] + 522 9 UIKit 0x00000001014b9998 -[UIWindow _sendTouchesForEvent:] + 735 10 UIKit
0x00000001014ba2c2 -[UIWindow sendEvent:] + 682 11 UIKit
0x0000000101480581 -[UIApplication sendEvent:] + 246 12 UIKit
0x000000010148dd1c _UIApplicationHandleEventFromQueueEvent + 18265 13
UIKit 0x00000001014685dc
_UIApplicationHandleEventQueue + 2066 14 CoreFoundation 0x0000000100b00431
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 15 CoreFoundation 0x0000000100af62fd
__CFRunLoopDoSources0 + 269 16 CoreFoundation 0x0000000100af5934 __CFRunLoopRun + 868 17 CoreFoundation
0x0000000100af5366 CFRunLoopRunSpecific + 470 18 GraphicsServices
0x0000000104bb3a3e GSEventRunModal + 161 19 UIKit
0x000000010146b900 UIApplicationMain + 1282 20 iKnizÃånica
0x00000001005c6377 main + 135 21 libdyld.dylib
0x0000000102e8f145 start + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException (lldb)
I posted the source code here: http://pastebin.com/M9AMakGr
Problem is not in the button settings, but in function
Instead of:
func saveTapped(){
Should be:
func saveTapped(sender:UIButton){
Change your setRightBarButtonItem code to below code:
self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "saveTapped:"), animated: true)
In swift, for selector you just need to type the name of the function, that's it! Hope it helps

Why unknown selector when calling JSONRPC on XBMC?

can someone give me a hint why i always geht an
"DSJSONRPC doesNotRecognizeSelector" when calling jsonrpc interface from XBMC?
Result in console:
*** JSON-RPC REQUEST:
{
id = 654509193;
jsonrpc = "2.0";
method = "Player.GetActivePlayers";
params = {
};
}
Code:
DSJSONRPC *jsonRPC = [[DSJSONRPC alloc] initWithServiceEndpoint:[NSURL URLWithString:#"http://192.168.1.101:8080/jsonrpc"]];
[jsonRPC callMethod:#"Player.GetActivePlayers" withParameters:#{ }
onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError* internalError)
Using DSJSONRPC from Demiurgic JSON RPC
Can't find the error - on XBMC a movie is playing at this time...
Thanks in advance,
cheese
here the error stack:
2013-12-22 22:02:52.846 XBMCapp[3529:70b] *** JSON-RPC REQUEST:
{
id = "-1698136466";
jsonrpc = "2.0";
method = "Player.GetActivePlayers";
params = {
};
}
2013-12-22 22:02:52.847 XBMCapp[3529:70b] Error:<DSJSONRPC: 0x95c11b0>
2013-12-22 22:02:52.847 XBMCapp[3529:70b] -[DSJSONRPC localizedDescription]: unrecognized selector sent to instance 0x95c11b0
2013-12-22 22:02:52.873 XBMCapp[3529:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DSJSONRPC localizedDescription]: unrecognized selector sent to instance 0x95c11b0'
*** First throw call stack:
(
0 CoreFoundation 0x01ef25e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018058b6 objc_exception_throw + 44
2 CoreFoundation 0x01f8f903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01ee290b ___forwarding___ + 1019
4 CoreFoundation 0x01ee24ee _CF_forwarding_prep_0 + 14
5 XBMCapp 0x000109ab -[DSJSONRPC callMethod:withParameters:onCompletion:] + 477
6 XBMCapp 0x000054df -[RootViewController nowplayingAction:] + 298
7 libobjc.A.dylib 0x01817874 -[NSObject performSelector:withObject:withObject:] + 77
8 UIKit 0x004780c2 -[UIApplication sendAction:to:from:forEvent:] + 108
9 UIKit 0x0074cc9b -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 139
10 libobjc.A.dylib 0x01817874 -[NSObject performSelector:withObject:withObject:] + 77
11 UIKit 0x004780c2 -[UIApplication sendAction:to:from:forEvent:] + 108
12 UIKit 0x0047804e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
13 UIKit 0x005700c1 -[UIControl sendAction:to:forEvent:] + 66
14 UIKit 0x00570484 -[UIControl _sendActionsForEvents:withEvent:] + 577
15 UIKit 0x0056f733 -[UIControl touchesEnded:withEvent:] + 641
16 UIKit 0x004b551d -[UIWindow _sendTouchesForEvent:] + 852
17 UIKit 0x004b6184 -[UIWindow sendEvent:] + 1232
18 UIKit 0x00489e86 -[UIApplication sendEvent:] + 242
19 UIKit 0x0047418f _UIApplicationHandleEventQueue + 11421
20 CoreFoundation 0x01e7b83f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
21 CoreFoundation 0x01e7b1cb __CFRunLoopDoSources0 + 235
22 CoreFoundation 0x01e9829e __CFRunLoopRun + 910
23 CoreFoundation 0x01e97ac3 CFRunLoopRunSpecific + 467
24 CoreFoundation 0x01e978db CFRunLoopRunInMode + 123
25 GraphicsServices 0x02d889e2 GSEventRunModal + 192
26 GraphicsServices 0x02d88809 GSEventRun + 104
27 UIKit 0x00476d3b UIApplicationMain + 1225
28 XBMCapp 0x0000234b main + 93
29 libdyld.dylib 0x02a2a70d start + 1
30 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
ok, found the problem - perhaps I have an old version of the JSON class...
There was an uninitialised error variable...
changing it to nil then everything works like a charm.
thanks anyway :)

Resources