goal c – Easy methods to save ics file to iOS calendar app utilizing UIActivityViewController?

0
2
goal c – Easy methods to save ics file to iOS calendar app utilizing UIActivityViewController?


Utilizing UIActivityViewController, I’m able to share eg Save a contact to Apple’s Contacts app. Nevertheless, when I attempt to one thing analagous for a Process within the type of an ics file, UIActityController will not be displaying an choice to avoid wasting to Calendar.

When the consumer faucets share, my app packages the duty as an .ics file and opens the UIActivityController which reveals the .ics file because the merchandise to share full with a calendar icon.

Nevertheless, the choice to avoid wasting to Calendar will not be proven, solely an choice to Copy or Save to Information. The Calendar app is put in on the simulator.

I do know getting the UIActivityViewController to acknowledge apps for sharing may be tough, however is there any technique to drive it to indicate the choice of save to Calendar within the case of an .ics file? (Code beneath is Goal-C however any Swift resolution can be nice too.)

Right here is the code to launch the activityViewController:

NSURL*icsurl = [self getICSURLFromItem:_item];
    
NSArray *activityItems;

if (picture == nil) {
    activityItems = @[text,icsurl];
}
else {
    activityItems =@[image,text,icsurl];
}
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems: activityItems applicationActivities:nil];

[self presentViewController:activityViewController animated:YES completion:nil];


//And code to create ics file verified working

-(NSURL*) getICSURLFromItem:(Objects *)merchandise {
    //construct ICS
    NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
    //required
    [mutableArray addObject:@"BEGIN:VCALENDAR"];
    [mutableArray addObject:@"VERSION:2.0"];
    [mutableArray addObject:@"PRODID:-//Acme Inc//Acme//EN"];
    [mutableArray addObject:@"METHOD:PUBLISH"];
    [mutableArray addObject:@"BEGIN:VEVENT"];
    [mutableArray addObject:item.summary];
    [mutableArray addObject:item.description];
    [mutableArray addObject:item.timezone];
    [mutableArray addObject:item.start];
    [mutableArray addObject:item.end];
    [mutableArray addObject:item.stamp];
    [mutableArray addObject:item.last];
    [mutableArray addObject:statusconfirmed];
    [mutableArray addObject:sequence];
  
    NSString * storedusername = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
    NSString * storedemail = [[NSUserDefaults standardUserDefaults] objectForKey:@"emailAddress"];
    NSString *organizer =[NSString stringWithFormat:@"ORGANIZER;CN="%@ at Acme":mailto:%@",storedusername,storedemail];
    [mutableArray addObject:organizer];
   
    [mutableArray addObject:@"END:VEVENT"];
    
    [mutableArray addObject:@"END:VCALENDAR"];
   
    NSString *ICSString = [mutableArray componentsJoinedByString:@"n"];
    NSString *ICSFilePath;
    NSString *humanFileName = merchandise.process;
    NSString *fullFileName = [humanFileName stringByAppendingString: @".ics"];
    ICSFilePath = [cachesPathString  stringByAppendingPathComponent:fullFileName];
    [ICSString writeToFile:ICSFilePath atomically:YES encoding:NSUnicodeStringEncoding error:nil];
           
    NSURL * ICSURL = [[NSURL alloc] initFileURLWithPath:ICSFilePath];
    return ICSURL;
}

On the simulator it does present an choice to repeat or save to information however that’s it. The simulator does have Calendar put in.

LEAVE A REPLY

Please enter your comment!
Please enter your name here