How to fire event by using Xcode?
I want开发者_如何学Go to develop an iphone app which communicate with the hardware by using tcp/ip. Now, the app send to the hardware is ok. For the convenience to develop, i want to use fire event to develop the receiver. Does anyone has any ideas?
Joe
To raise an event:
[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:someObj];
To listen for the event:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:notificationName object:notificationSender];
To stop listening for the event:
[[NSNotificationCenter defaultCenter] removeObserver:self name:notificationName object:notificationSender];
More here
add 2 frameworks
1.EventKitUI.framework
2.EventKit.framework
.m
#import <EventKitUI/EventKitUI.h>
- (IBAction)CreateEvent:(id)sender {
//Get the even store object
//EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEventStore *eventStore = [[EKEventStore alloc] init];
/* iOS 6 requires the user grant your application access to the Event Stores */
if([[UIDevice currentDevice].systemVersion floatValue] >= 6.0)// checks if device is ios6
{
[eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
// handle access here
}];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
// iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if ( granted )
{
NSLog(@"User has granted permission!");
}
else
{
NSLog(@"User has not granted permission!");
}
}];
}
EKEventEditViewController *controller=[[EKEventEditViewController alloc]init];
controller.eventStore=eventStore;
controller.editViewDelegate=self;
controller.wantsFullScreenLayout=YES;
[self presentModalViewController:controller animated:YES];
}
else
{
EKEventEditViewController *controller=[[EKEventEditViewController alloc]init];
controller.eventStore=eventStore;
controller.editViewDelegate=self;
controller.wantsFullScreenLayout=YES;
[self presentModalViewController:controller animated:YES];
}
}
- (void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action
{
// [Bw alert:@"Done"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" Done" message:@"Event Sucessfully Saved " delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
@end
精彩评论