NHCalendarActivity 0.0.3

NHCalendarActivity 0.0.3

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

Otavio Cordeiro 维护。



  • 作者
  • Otavio Cordeiro

NHCalendarActivity 是一个易于使用的自定义 UIActivity (iOS 6+),可以向 iOS 日历添加事件和闹钟。

如何安装它?

CocoaPods 是安装 NHCalendarActivity 的最简单方式。运行 pod search NHCalendarActivity 搜索最新版本。

然后,将 pod 行复制到您的 Podfile 中。您的 podfile 应该如下所示

platform :ios, '6.0'
pod 'NHCalendarActivity', '~> 0.0.1'

最后,通过运行 pod install 来安装。

如何使用它?

首先,创建一个事件实例的 NHCalendarEvent(请注意,您可以包括闹钟)

-(NHCalendarEvent *)createCalendarEvent
{
    NHCalendarEvent *calendarEvent = [[NHCalendarEvent alloc] init];

    calendarEvent.title = @"Long-expected Party";
    calendarEvent.location = @"The Shire";
    calendarEvent.notes = @"Bilbo's eleventy-first birthday.";
    calendarEvent.startDate = [NSDate dateWithTimeIntervalSinceNow:3600];
    calendarEvent.endDate = [NSDate dateWithTimeInterval:3600
                                               sinceDate:calendarEvent.startDate];
    calendarEvent.allDay = NO;

    // Add alarm
    NSArray *alarms = @[
        [EKAlarm alarmWithRelativeOffset:- 60.0f * 60.0f * 24],  // 1 day before
        [EKAlarm alarmWithRelativeOffset:- 60.0f * 15.0f]        // 15 minutes before
    ];
    calendarEvent.alarms = alarms;

    return calendarEvent;
}

然后,使用 NHCalendarEvent 和 NHCalendarActivity 初始化 UIActivityViewController

- (IBAction)openBtnTouched:(id)sender
{
    NSString *msg = NSLocalizedString(@"NHCalendarActivity", nil);
    NSURL* url = [NSURL URLWithString:@"http://git.io/LV7YIQ"];

    NSArray *activities = @[
        [[NHCalendarActivity alloc] init]
    ];

    NSArray *items = @[
        msg,
        url,
        [self createCalendarEvent]
    ];

    UIActivityViewController* activity = [[UIActivityViewController alloc] initWithActivityItems:items
                                                                           applicationActivities:activities];

    [self presentViewController:activity
                       animated:YES
                     completion:NULL];    
}

还有一个 NHCalendarActivityDelegate 协议,可以使用它来执行附加操作

#pragma mark - NHCalendarActivityDelegate

-(void)calendarActivityDidFinish:(NHCalendarEvent *)event
{
    NSLog(@"Event created from %@ to %@", event.startDate, event.endDate);
}

-(void)calendarActivityDidFail:(NHCalendarEvent *)event
                     withError:(NSError *)error
{
    NSLog(@"Ops!");
}

- (void)calendarActivityDidFailWithError:(NSError *)error
{
    NSLog(@"Ops!");
}

就这样。

查看效果

NHCalendarActivity

许可证

版权所有 (c) 2012 Otavio Cordeiro。保留所有权利。

特此授予任何获得该软件及其相关文档文件副本(“软件”)的人免费使用权,无限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许软件提供方执行上述操作,前提是符合以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“现状”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和无侵犯性的保证。在任何情况下,作者或版权持有人不对任何索赔、损害或其他责任承担责任,无论此类责任是基于合同、侵权或其他方式产生的,只要此类责任源于、产生于或与软件或使用或otherwise related to the software.