builttoroam / device_calendar

A cross platform plugin for modifying calendars on the user's device
https://pub.dev/packages/device_calendar
BSD 3-Clause "New" or "Revised" License
270 stars 271 forks source link

iOS createCalendar error: Local calendar was not found #223

Open thiszhong opened 4 years ago

thiszhong commented 4 years ago

It occurs on my real iPhone device(iPhone 7, iOS 13.3.1 et.), while simulator and android are OK. I tried both my app and the demo.

[599] Device calendar plugin ran into an issue. Platform specific exception [500], with message: "Local calendar was not found.", has been thrown.

WechatIMG1

flutter doctor -v
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.4 19E287, locale zh-Hans-CN)
    • Flutter version 1.17.0 at /Users/zhong/code/flutter
    • Framework revision e6b34c2b5c (10 days ago), 2020-05-02 11:39:18 -0700
    • Engine revision 540786dd51
    • Dart version 2.8.1

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/zhong/Library/Android/sdk
    • Platform android-29, build-tools 28.0.3
    • ANDROID_HOME = /Users/zhong/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    • CocoaPods version 1.9.0

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.3.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.44.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.10.1

[!] Connected device
    ! No devices available
thiszhong commented 4 years ago

Seems to be the iCloud. When I close it by setting-account-iCloud-Calendar, createCalendar successed. Is there any solution?

zeshanghayoomi commented 4 years ago

are you guys gonna release the fix for this anytime soon ?

michaelchiowong commented 3 years ago

hi, guys, any updates for this issue?

sj1914 commented 3 years ago

+100 in favour of a fix for this

amrothemich commented 3 years ago

Has anyone come up with a way to handle this?

amrothemich commented 3 years ago

So I have zero experience or understanding of Swift so don't use this without checking it and testing it, but I adapted https://nemecek.be/blog/45/how-to-create-new-calendar-using-eventkit-in-swift to solve this problem and it seems to work for me.

Replace createCalendar() in SwiftDeviceCalendarPlugin.swift with:

private func createCalendar(_ call: FlutterMethodCall, _ result: FlutterResult) {
        do {
            let arguments = call.arguments as! Dictionary<String, AnyObject>
            let calendar = EKCalendar(for: .event, eventStore: eventStore)
            calendar.title = arguments[calendarNameArgument] as! String
            calendar.cgColor = UIColor.purple.cgColor

            let `default` = eventStore.defaultCalendarForNewEvents?.source
            let iCloud = eventStore.sources.first(where: { $0.title == "iCloud" }) // this is fragile, user can rename the source
            let local = eventStore.sources.first(where: { $0.sourceType == .local })

            let source = iCloud ?? `default` ?? local
            if (source != nil) {
                calendar.source = source
                try! eventStore.saveCalendar(calendar, commit: true)
                result(calendar.calendarIdentifier)
            } else {
                result(FlutterError(code: self.genericError, message: "Local calendar was not found.", details: nil))
            }

        } catch {
            eventStore.reset()
            result(FlutterError(code: self.genericError, message: error.localizedDescription, details: nil))
        }

    }

If somebody takes a look at it, I'd be glad to submit a PR.

EDIT: Oops, I didn't do color setting. will do this later and update.

arslan9380 commented 2 years ago

any solution found so far?

thomassth commented 2 years ago

The post above seems to solve things

But I don't have xcode on my hand, so I can't make the PR on my own and test it

If anyone wants to submit said PR I would check it asap