Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support to iOS 13.0 and Above #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

mlch911
Copy link

@mlch911 mlch911 commented Apr 24, 2023

No description provided.

@yuta-shoji
Copy link

yuta-shoji commented May 5, 2023

@a2
Hello,
Nice to meet you, I'm Yuta Shoji.

Although this issue is not related to this Issue since the issue of this repository has been disabled,
may I ask some questions here?
This is a question about implementing HelloWorldShortcut as it is in the README.

❶ Cannot write to data
I implemented the following code in AppDelegate, according to the README:

let shortcut = HelloWorldShortcut()
let data = try shortcut.build()
try data.write(to: URL(fileURLWithPath: "Hello World.shortcut"))

However, I get the error message You can’t save the file “HelloWorld4.shortcut” because the volume “Data” is read only. So, I changed it to the following code:

        let shortcut = HelloWorldShortcut()
        do {
            let data = try shortcut.build()

            let documentsDirectory = NSSearchPathForDirectoriesInDomains(
                .documentDirectory,
                .userDomainMask,
                true
            )[0]

            let filePath = documentsDirectory.appending("/HelloWorld5.shortcut")
            let fileUrl = URL(fileURLWithPath: filePath)
            try data.write(to: fileUrl)

            print("Shortcut added to library")
        } catch (let error) {
            print(error.localizedDescription)
        }

With this change, I was able to write to the data. Did you intend to make this change?

❷ Custom shortcut not added to Shortcuts app
Although the error message above no longer appears, the custom shortcut is not added. Is it impossible to implement this as described in the README? If it is possible, could you please give me some advice?

Thank you very much.

@mlch911
Copy link
Author

mlch911 commented May 5, 2023

@a2 Hello, Nice to meet you, I'm Yuta Shoji.

Although this issue is not related to this Issue since the issue of this repository has been disabled, may I ask some questions here? This is a question about implementing HelloWorldShortcut as it is in the README.

❶ Cannot write to data I implemented the following code in AppDelegate, according to the README:

let shortcut = HelloWorldShortcut()
let data = try shortcut.build()
try data.write(to: URL(fileURLWithPath: "Hello World.shortcut"))

However, I get the error message You can’t save the file “HelloWorld4.shortcut” because the volume “Data” is read only. So, I changed it to the following code:

        let shortcut = HelloWorldShortcut()
        do {
            let data = try shortcut.build()

            let documentsDirectory = NSSearchPathForDirectoriesInDomains(
                .documentDirectory,
                .userDomainMask,
                true
            )[0]

            let filePath = documentsDirectory.appending("/HelloWorld5.shortcut")
            let fileUrl = URL(fileURLWithPath: filePath)
            try data.write(to: fileUrl)

            print("Shortcut added to library")
        } catch (let error) {
            print(error.localizedDescription)
        }

With this change, I was able to write to the data. Did you intend to make this change?

❷ Custom shortcut not added to Shortcuts app Although the error message above no longer appears, the custom shortcut is not added. Is it impossible to implement this as described in the README? If it is possible, could you please give me some advice?

Thank you very much.

❶ Cannot write to data:

I assume you're running this on a ipad.
If it's on a ios device, you are right, it can't write data to current folder. (Because ios run every app in a sandbox.)
You can save the file to another location, just like your code, to document directory.

❷ Custom shortcut not added to Shortcuts app:

It's possible to add the .shourtcut file to Shortcuts app.
You can see what I changed in this PR, I add a sign function. It can only run on a mac, and use mac's shell to sign the .shourtcut file. (I didn't find any way to run this on ios device.)

let shortcut = HelloWorldShortcut()
try shortcut.buildAndSave(atPath: URL(fileURLWithPath: "HelloWorld.shortcut"))

After sign the file, you can drag the file into Shortcuts app.

@mlch911
Copy link
Author

mlch911 commented May 5, 2023

@a2 Any chance this PR can be merged soon ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants