如何使用Xcode触发事件?

时间:2010-06-25 03:21:14

标签: iphone xcode events

我想开发一个使用tcp / ip与硬件通信的iphone应用程序。 现在,应用程序发送到硬件是好的。 为了方便开发,我想用fire事件来开发接收器。 有没有人有任何想法?

2 个答案:

答案 0 :(得分:6)

举办活动:

[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:someObj];

听取此事件:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationSelector:) name:notificationName object:notificationSender];

停止收听活动:

[[NSNotificationCenter defaultCenter] removeObserver:self name:notificationName object:notificationSender];

More here

答案 1 :(得分:1)

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