Programmatically add reminder to iPhone calendar? - iphone

Can anyone have any idea about programmatically add reminder to iPhone calendar.
I searched the iPhone SDK documentation but didn't find anything.
Thanks and Regards
Jayaraj

This functionality is available in iOS 4.x with EventKit.

You could try to read this EventKit sample.

Oh yes you can...
#import <EventKit/EventKit.h>
...
EKEventStore *eventDB = [[EKEventStore alloc] init];
EKEvent *myEvent = [EKEvent eventWithEventStore:eventDB];
myEvent.title = #"New Event";
myEvent.startDate = [[NSDate alloc] init];
myEvent.endDate = [[NSDate alloc] init];
myEvent.allDay = NO;
myEvent.notes = #"Test";
[myEvent setCalendar:[eventDB defaultCalendarForNewEvents]];
NSError *err;
[eventDB saveEvent:myEvent span:EKSpanThisEvent error:&err];
if (err == noErr) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Event Created"
message:#"Yay!?"
delegate:nil
cancelButtonTitle:#"Okay"
otherButtonTitles:nil];
[alert show];
[alert release];
}

You can't. If you need this functionality you should file a bug with Apple explaining why you need it.

Related

Adding events not saving into my iphone Calendar

I am using the following code to add an event to my calendar, but it's not showing any error neither saving into my calendar. Please help.
EKEventStore *eventstore = [[EKEventStore alloc] init];
if([eventstore respondsToSelector:#selector(requestAccessToEntityType:completion:)])
{
[eventstore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if(granted)
{
// if user granted your app to use calendar control will reach over hare
// add the code to add event to iCal that you are using previously for iOS5
EKEvent *event = [EKEvent eventWithEventStore: eventstore];
event.title = #"Title";
event.notes = #"Description";
event.location = #"Location";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:#"UTC"];
[dateFormat setTimeZone:timeZone];
[dateFormat setDateFormat:#"dd-MM-yyyy hh:mm a"];
NSDate *date = [dateFormat dateFromString:[NSString stringWithFormat:#"%#",[[eventsArray objectAtIndex:index] objectForKey:#"EventDate"]]];
event.startDate =date;
event.endDate = [date dateByAddingTimeInterval:36000];;
event.availability = EKEventAvailabilityFree;
[event setCalendar:[eventstore defaultCalendarForNewEvents]];
NSError *err;
[eventstore saveEvent:event span:EKSpanThisEvent error:&err];
}
else
{
NSLog(#"Calender not called");
// if user did not your app to use calendar control will reach over hare
}
}];
}
First i have added eventkit framework, then #import EventKit/EventKit.h into <> added to my view controller, and then implemented a code as below, and it worked fine for me hope you can also find solution by referring this :)
-(IBAction)AddEvent:(id)sender
{
EKEventStore *eventStore = [[EKEventStore alloc] init];
if([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)]) {
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted){
//---- codes here when user allow your app to access theirs' calendar.
[self performCalendarActivity:eventStore];
}else
{
//----- codes here when user NOT allow your app to access the calendar.
}
}];
}
else {
//---- codes here for IOS < 6.0.
[self performCalendarActivity:eventStore];
}
}
-(void)performCalendarActivity:(EKEventStore *)eventStore
{
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
if([txtTitle.text isEqualToString:#""] || txtTitle.text == NULL)
txtTitle.text=#"Event Title";
event.title= txtTitle.text;
NSDate *duedate = pkrDate.date;
event.startDate =duedate;
event.endDate= [[NSDate alloc] initWithTimeInterval:600 sinceDate:duedate];
if(switchAlarm.on==TRUE){
NSArray *arrAlarm = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:duedate]];
event.alarms= arrAlarm;
}
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
BOOL isSuceess=[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
if(isSuceess){
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"Event" message:#"Event added in calendar" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertview show];
[alertview release];
}
else{
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"Event" message:[err description] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertview show];
[alertview release];
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
I had same problem no errors but no event in calendar.
Check iphone settings:icloud:calendars switch is turned ON.

How can I set Multiple Alarm with Notification in iphone

I need to set the alarm with notification in my App I have try the following codes but no luck for me
EKEventStore * eventStore1 = [[EKEventStore alloc] init];
if([eventStore1 respondsToSelector:#selector(requestAccessToEntityType:completion:)]) {
[eventStore1 requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
// This code will run when uses has made his/her choice
EKEvent *event = [EKEvent eventWithEventStore:eventStore1];
NSDate * date = [NSDate date];
NSLog(#"%#",date);
event.title = #"HAIManiiiiii";
event.location = #" ";
event.startDate = date;
event.endDate = [[[NSDate alloc] initWithTimeInterval:36 sinceDate:event.startDate] autorelease];
EKRecurrenceRule *rule = [[EKRecurrenceRule alloc]
initRecurrenceWithFrequency:EKRecurrenceFrequencyYearly
interval:1
end:[EKRecurrenceEnd recurrenceEndWithOccurrenceCount:10]];
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:-36];
NSArray * ruleArray = [[NSArray alloc]initWithObjects:rule, nil];
NSArray * alrmArray = [[NSArray alloc] initWithObjects: alarm1, nil];
event.alarms = alrmArray;
event.recurrenceRules = ruleArray;
[event setCalendar:[eventStore1 defaultCalendarForNewEvents]];
NSError *err;
// [eventStore1 saveEvent:event span:EKSpanThisEvent error:&err];
NSLog(#"%d",[eventStore1 saveEvent:event span:EKSpanThisEvent error:&err]);
NSLog(#"Error From iCal : %#", [err description]);
}]
The event and is adding to the calendar by its not working for me.Please suggest me some idea to fix this issue
Use following code. It probably worked fine for me.
EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];
if([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)]) {
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted){
//---- codes here when user allow your app to access theirs' calendar.
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"My Event";
event.notes =#"";
NSLog(#"%#",[StartTimePicker date]);
event.startDate = [StartTimePicker date];
// event.startDate = delegate.SelectedDate;
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
EKAlarm *alarm=[EKAlarm alarmWithRelativeOffset:600];
[event addAlarm:alarm];
BOOL Save= [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSLog(#"%d",Save);
if (Save) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Success" message:#"Alarm set" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
[DejalBezelActivityView removeViewAnimated:YES];
}
}else
{
[DejalBezelActivityView removeViewAnimated:YES];
//----- codes here when user NOT allow your app to access the calendar.
NSLog(#"Permission not allowed");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Permissions not allowed" message:#"Please allow access permission in Calendar setting" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}];
}
else {
//---- codes here for IOS < 6.0.
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"My Event";
event.startDate =dt;
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
EKAlarm *alarm=[EKAlarm alarmWithRelativeOffset:600];
[event addAlarm:alarm];
BOOL Save= [eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSLog(#"%d",Save);
if (Save) {
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Success" message:#"Alarm set" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
}

UIActivityViewController Background Color

So I have a UIActivityViewController in my Application. How do I change the background color.
And I also have a quick how to add Facebook and twitter to my UIActivityViewController.
The Code:
- (IBAction)Social:(id)sender {
UIActivityViewController *social = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:#"Travel+ Rocks",nil] applicationActivities:nil];
social.excludedActivityTypes = #[UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypePostToWeibo,UIActivityTypePrint];
[self presentViewController:social animated:YES completion:nil];
[social setCompletionHandler:^(NSString *activityType, BOOL completed)
{
NSLog(#"Activity = %#",activityType);
NSLog(#"Completed Status = %d",completed);
if (completed)
{
// UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Your Posts were sucessful" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
// [objalert show];
// objalert = nil;
}else
{
// UIAlertView *objalert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Your Posts weren't sucessful" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
// [objalert show];
// objalert = nil;
}
}];
}
These Piece of Code fix the Background Eror:
NSString *message = [NSString stringWithFormat:#""];
NSString *textToShare = message;
UIImage *imageToShare = [UIImage imageNamed:#""];
NSArray *activityItems = [[NSArray alloc] initWithObjects:textToShare, imageToShare,nil];
UIActivity *activity = [[UIActivity alloc] init];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
[self presentViewController:activityVC animated:YES completion:nil];
Have a look on the following linked sample code you may get some idea...
https://github.com/coryalder/DMActivityInstagram/downloads
if you set the targets -> summary -> status Bar style the color of the share view will follow. that the best iv found out .....
hope it helps

How implement scheduling event with post a message on fb

I am creating an application in which I have add a facility for post message on ur account. Now this facility I am adding an event for scheduling. With help of that user can write a message and post that later or on particular date and time. For this I used a local notification event which is generate on given date by user. But problem is that when notification generate then I have call a function which is used for post message on Facebook. For generate notification I have used this code:
-(IBAction)save{
NSString *str1=[NSString stringWithFormat:#"%#",txt_date.text];
NSString *str2=[NSString stringWithFormat:#" %#",txt_time.text];
str1=[str1 stringByAppendingFormat:str2];
selected_label.text= str1;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSDate *today=[NSDate date];
NSDateFormatter* formatter_current = [[[NSDateFormatter alloc] init] autorelease];
formatter_current.timeZone = [NSTimeZone timeZoneWithAbbreviation:#"GMT"];
//Set the required date format
[formatter_current setDateFormat:#"yyyy-MM-dd hh:mm a"];
NSLog(#"current date is =%#",str1);
today=[formatter_current dateFromString:str1];
NSLog(#"current date:-%#",today);
UILocalNotification* ln = [[UILocalNotification alloc] init];
ln.alertBody = #"Wake Up Sid";
ln.applicationIconBadgeNumber = 1;
ln.fireDate = today; //[NSDate dateWithTimeIntervalSinceNow:15];
ln.timeZone = [NSTimeZone timeZoneWithAbbreviation:#"GMT"];
NSLog(#"alarm will activate on%#",today);
NSDateFormatter* formatter_alarm = [[[NSDateFormatter alloc] init] autorelease];
NSLocale *uslocale = [[NSLocale alloc] initWithLocaleIdentifier:#"en_US"];
[formatter_alarm setLocale:uslocale];
[uslocale release];
formatter_alarm.timeZone = [NSTimeZone timeZoneWithAbbreviation:#"GMT"];
[formatter_alarm setDateFormat:#"hh:mm a"];
NSString *str=[formatter_alarm stringFromDate:today];
NSLog(#"%#",str);
ln.alertBody = [NSString stringWithFormat:#"Your first appointment at %#",str];
ln.soundName = UILocalNotificationDefaultSoundName;
ln.repeatInterval=NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:ln];
[ln release];
}
and in appdelegate file I use this function for received notification and call post message function:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// Override point for customization after application launch.
self.viewController=[[demo_social_updatesViewController alloc]initWithNibName:#"demo_social_updatesViewController" bundle:nil];
nav_controller=[[UINavigationController alloc] initWithRootViewController:self.viewController];
// Add the view controller's view to the window and display.
[self.window addSubview:nav_controller.view];
[self.window makeKeyAndVisible];
appDelegate_acess_token=[[NSUserDefaults standardUserDefaults] stringForKey:#"access_token"];
application.applicationIconBadgeNumber = 0;
// Handle launching from a notification
UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSLog(#"Recieved Notification %#",localNotif);
}
return YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application{
if (application.applicationIconBadgeNumber == 1) {
BOOL tmp=[Global_Class_parsing post_comment_fb:appDelegate_acess_token uesr_comment:#"testing message111"];
if(tmp){
UIAlertView *av = [[[UIAlertView alloc] initWithTitle:#"Sucessfully posted to photos & wall!"
message:#"Check out your Facebook to see!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[av show];
}
else{
UIAlertView *av = [[[UIAlertView alloc] initWithTitle:#"error"message:#"Check connection!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[av show];
}
}
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application{
/*
Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
*/
if (application.applicationIconBadgeNumber == 1) {
BOOL tmp=[Global_Class_parsing post_comment_fb:appDelegate_acess_token uesr_comment:#"testing message111"];
if(tmp){
UIAlertView *av = [[[UIAlertView alloc] initWithTitle:#"Sucessfully posted to photos & wall!"
message:#"Check out your Facebook to see!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[av show];
}
else{
UIAlertView *av = [[[UIAlertView alloc] initWithTitle:#"error"message:#"Check connection!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[av show];
}
}
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
NSLog(#"Recieved Notification %#",notification);
} else {
NSLog(#"Recieved Notification method call.");
}
}
Now problem is that when notification generate and applicationbadge number become 1 then it not call any function and my post message function not calling. So how I fix that error?
I get solution for this question is that i have two way to implement scheduling with post method one is simply use notification. And another is use web-service. I have used both and working well.

How to add events in iPhone using Event Kit framework

I am making a Restaurant application in which i need to add events in calendar, events information are coming from server, if client add any event it should show in calendar for that specified date, i have used event kit frame work and successfully added one event into the calendar, however how to add multiple events in calendar using event kit.
First of All, Add EventKit Framework and import it in .h file. Like below.
#import <EventKit/EventKit.h>
See Below Function and Modify it as per your need.
-(IBAction)AddEvent:(id)sender{
EKEventStore *eventSotre = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventSotre];
if([txtTitle.text isEqualToString:#""] || txtTitle.text == NULL)
txtTitle.text=#"Event Title";
event.title= txtTitle.text;
NSDate *duedate = pkrDate.date;
event.startDate =duedate;
event.endDate= [[NSDate alloc] initWithTimeInterval:600 sinceDate:duedate];
if(switchAlarm.on==TRUE){
NSArray *arrAlarm = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:duedate]];
event.alarms= arrAlarm;
}
[event setCalendar:[eventSotre defaultCalendarForNewEvents]];
NSError *err;
BOOL isSuceess=[eventSotre saveEvent:event span:EKSpanThisEvent error:&err];
if(isSuceess){
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"Event" message:#"Event added in calendar" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertview show];
[alertview release];
}
else{
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"Event" message:[err description] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertview show];
[alertview release];
}
[eventSotre release];
}
Please modify it as per your need. I just paste it from my one of app code.