HomeiOS DevelopmentHow one can save ics file to IOS calendar app utilizing UIActivityViewController...

How one can save ics file to IOS calendar app utilizing UIActivityViewController utilizing Swift or Goal-C


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 Activity within the type of an ics file, UIActiityController isn’t exhibiting an choice to avoid wasting to Calendar.

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

Nevertheless, the choice to avoid wasting to Calendar isn’t proven, solely an choice to repeat or save to Recordsdata. The calendar app is put in on the simulator.

I do know getting the UIActivityViewController to acknowledge apps for sharing may be difficult, however is there any technique to drive it to proven the choice of save to Calendar within the case of an .ics file? (Code under is objc however any Swift answer could be nice too.)

Thanks upfront for any recommendations.

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:(Gadgets *)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 recordsdata however that’s it. The simulator does have Calendar put in. Thanks for any recommendations.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments