DjimOnDev
DjimOnDev

Reputation: 399

open calendar from uibutton

I made many and many search to find a way to open native calendar app from a UIButton in my app. I can't find the way to do it from UIButton.

The only way i found to do this is putting a date in a webview and activate the event detection.

Can someone find how it can by by this method below ?

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"calendrier"]];

Upvotes: 0

Views: 635

Answers (1)

DjimOnDev
DjimOnDev

Reputation: 399

I found a mean to do this. This is not really a mean using a UIButton, but it works !

  1. put an image on your uiview with your icon.
  2. put a webview (called webViewBtn) on this icon
  3. code !
    NSString *path = [[NSBundle mainBundle] pathForResource:@"agenda-button" ofType:@"html"];
    NSURL *baseURL = [NSURL fileURLWithPath:path];
    NSString *fileText = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    NSMutableString *agendaButton = [[NSMutableString alloc] initWithFormat:fileText, date2openInCalendar];
    [webViewBtn loadHTMLString:agendaButton baseURL:baseURL];

and put a HTML file in your project named "agenda-button.html" with those lines :

<html>
<head>
    <style type="text/css">
        <!--
        html,body,p,a{
            display: block;
            width: 60px;
            height: 40px;
            /*background: url(btn_agenda.png) top left no-repeat;*/
            text-indent: -9999px;
                            font-size: 1px;
            }
            -->
        </style>
    </head>
    <body>%@</body>
<html>

You will see an actionsheet with those choices : "create event", "show in calendar", "copy"

PS: allows events detection in the webview !

Upvotes: 1

Related Questions