How to call mac API "Adding a new event" in swift? - swift

I have an electron application, and a requirement is to call the mac's api to add related schedules, as shown in the figure:
I want to use swift for development, and then package it into a node addon for electron to call, but I am not very familiar with swift and mac api.
I don't know how to write related swift code and which api to call to complete the function of the above picture.
I tried AppleScript, but it seems that I can't choose calendar contains freely.
Here is the applescript code to try(unable to meet demand):
set theStartDate to (current date) + (1 * days)
set hours of theStartDate to 15
set minutes of theStartDate to 0
set seconds of theStartDate to 0
set theEndDate to theStartDate + (1 * hours)
tell application "Calendar"
tell calendar "Calendar Project"
make new event with properties {summary:"Important Meeting!", start date:theStartDate, end date:theEndDate}
end tell
end tell
Of course, if Objective-C and AppleScript can also do it, it is also possible.
Any hints would be helpful. Thanks!
If the above description does not describe the problem well, then I will ask in another way:
What API of macOS should be called in swift to pop up a Adding a new event window

The dialog in question is part of Calendar.app and AppleScript is the only way to invoke it, but this is clunky. The best way is to create your own UI and use EventKit to add the event based on the selections in the UI.

Related

NSWorkspace's 'frontmostApplication' doesn't change after initial use

I'm trying to get an update of the current active (foreground) application. Even across computer screens. I'm using this code to try to do it:
print(NSWorkspace.sharedWorkspace().frontmostApplication?.localizedName)
This loops in a command line application every 3 seconds, and prints to console. It works with any application open as active when it first starts up.
However, it does not change from the first app afterwards.
1. Why is it doing this?
2. What is the proper code to make it work?
3. Is there a way to simply get the app name every time the forefront application changes? (preferably in swift or obj-c)
Is there a way to simply get the app name every time the forefront application changes?
Use the NSWorkspace notification NSWorkspaceDidActivateApplicationNotification.

Issue with FilePicker in BlackBerry 10

I've being trying to implement a native File picker on BlackBerry 10 today, I linked it against the required Library -lbbcascadespickers
Included <bb/cascades/pickers/FilePicker> that links to the FilePicker.hpp class and all seems fine, but when I try to create a new File picker it says "error: 'FilePicker' was not declared in this scope"
Code is as follows:
FilePicker* filePicker = new FilePicker();
filePicker->setType(FileType::Picture);
filePicker->setTitle("Select Picture");
filePicker->setMode(FilePickerMode::Picker);
filePicker->open();
// Connect the fileSelected() signal with the slot.
QObject::connect(filePicker,
SIGNAL(fileSelected(const QStringList&)),
this,
SLOT(onFileSelected(const QStringList&)));
// Connect the canceled() signal with the slot.
QObject::connect(filePicker,
SIGNAL(canceled()),
this,
SLOT(onCanceled()));
I'm brand new to BlackBerry development so don't really know what to do, I've cleaned the project and built it many times but it won't play.
I was going by the example on BlackBerry's website:
https://developer.blackberry.com/native/reference/cascades/bb_cascades_pickers__filepicker.html
I wanted to open it from QML (I'm using Qt Quick and not BB components)
If anyone can help it will be deeply appreciated
The compiler can't find FilePicker. So either use a using to tell the compiler where to look:
using namespace bb::cascades::pickers;
or fully qualify the name of the class:
bb::cascades::pickers::FilePicker* filePicker = new FilePicker();

Auto Redial using iphone app

Two questions actually.
First : I know iPhone is missing auto-redialing functionality but is there any other way to achieve it by iPhone application, as I can call by my application but facing problem cannot auto redial.
Second : Before calling I want to implement functionality of loud-speaker on a button action.
Is there any way to achieve the above 2 functionalities?
I spent 4-5 hours on googgling about it and the result is only this
I go through to apples doc and found some code hereand also tried this but cant get the right way to implement above functions ...
Any help would be greatly appreciated!
Thanks!!!
Neither of those actions are possible with the SDK.
For the Second case it's definitely NO.
But for the First case, I have no sure about this, but can be tried:
Subscribe with the CTCallCenter for call states notifications and use some background application type (voip, location or audio) or use some waiting block, that will allow to prevent going to suspended state as long as possible
Open URL using tel://
If the call notification about call failure comes in, try to repeat opening an URL
Once again, just an idea, may not work at all :/

Add calendar to iphone

I am currently making and iphone app and a big function that i want to incorporate is the ability to subscribe to a calendar..
what i wish to do is to let the user give a URL for where the calendar is held, and from that url i want the app to fetch that calendar and subscribe to it..
i want to know how i can write the code to do this..
so in short my question is..
what code would i write to:
get .ics file from a URL
and save/subscribe to this newly
fetched .ics calendar file
any help and info would be very much appreciated..
The idea of "subscribing" to something isn't a build in function of the iOS SDK. To get this type of functionality would mean writing a recurring/timed function to grab the contents of this URL and process it locally.
The library I often use to simplify some of the HTTP functionality that you'll need is asi-http-request
https://github.com/pokeb/asi-http-request/tree
Hope this is helpful.

make the language of my IPHONE app change from the app settings without changing the language of the device

I want to make the language changeable from the application settings. For that I made a settings.bundle and i forced the langauge using this code How to force NSLocalizedString to use a specific language , I also put the UIApplicationExitsOnSuspend to YES to make my app reload every time it goes to the background.
It partially worked for me but I have 2 problems :
- The splash screen (which is localized) is not changing with this method.
- I must enter/goBack twice to make the language change effective on the application Views an this only on the OS 4 and higher.
Has anyone a solution for that?
You need to create you own translation framework for that ! Sorry !
Unfortunately there's no built-in way. What would be probably easiest would be integrate service like GetLocalization.com, so that your app would download language file via API (then it's easy to add new languages and translations even app is already released). Then what you need is just simple loader that loads that language file to memory and function that replaces the original string with translated one in run-time. You can calculate hash for original string so it's fast to search them, good algorithm for this is Peter Weinberger's hashPJW.
The trick to use specific language by selecting it from the app is to force the NSLocalizedString to use specific bundle depending on the selected language ,
here is the post i have written for this http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html
and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps