Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine that an EKCalendar is a Facebook calendar?

Tags:

ios

eventkit

Given any EKCalendar, how can I check if this calendar is a Facebook calendar? A Facebook calendar can be the Facebook events calendar or the Facebook birthdays calendar.

like image 206
Tom van Zummeren Avatar asked Feb 01 '26 19:02

Tom van Zummeren


2 Answers

Unfortunately, there's no way to tell whether a specific calendar is a facebook calendar without using private API.
I've filed a bug report during the beta of iOS 6 and an Apple engineer told me they'd fix it for the final release, but it turns out they didn't...

You can, however, test if a specific event is a facebook event:

BOOL isFacebookEvent = [[event.URL host] hasSuffix:@"facebook.com"];

This does not work for facebook birthday events, though!

like image 155
Fabian Kreiser Avatar answered Feb 03 '26 07:02

Fabian Kreiser


There is still no public API in EventKit for this, but there is a workaround using only public methods.

Each calendar has a color property: ekCalendar.CGColor

The Facebook event calendar's color is Facebook Blue, so by comparing the rbg components of the calendar color it is possible to determine a calendar is most likely from Facebook.

I wrote a swift extension to UIColor to check if a given color is Facebook Blue (complete with helper functions to make the UIColor rgb function more swift like)

extension UIColor {

    struct rgbComponents {
        var red : CGFloat
        var green : CGFloat
        var blue : CGFloat
        var alpha : CGFloat
    }

    func toComponents()->rgbComponents {
        var r:CGFloat = 0
        var g:CGFloat = 0
        var b:CGFloat = 0
        var a:CGFloat = 0

        var components : rgbComponents

        if self.getRed(&r, green: &g, blue: &b, alpha: &a) {
            components = rgbComponents(red: r, green: g, blue: b,  alpha: a)
        } else {
            components = rgbComponents(red: 0, green: 0, blue: 0, alpha: 0)
        }

        return components
    }

    func isFBBlue()->Bool {
        let c = self.toComponents()
        let result = c.red == 0.18823529779911041
                        &&  c.green == 0.39215686917304993
                        &&  c.blue == 0.7137255072593689
                        &&  c.alpha == 1.0
        return result
    }
like image 28
pjh68 Avatar answered Feb 03 '26 07:02

pjh68



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!