I am new into iOS Swift developing, so I do have many questions, sorry. What I want to have is saving only handwritten inputs at the same spots and load them at the same location, not need converted ones. So if I understood correctly, I should follow this page https://developer.myscript.com/docs/interactive-ink/1.3/ios/fundamentals/storage/. Or should I take the "import and export" section ?
If you have answered my question, can I provide some codes to check later ? Since I am new into coding, I have some problems with translating from Objective-C into Swift.
Thanks in advance!
Best Answer
T
Thanh Hoang
said
over 5 years ago
I could solve my problem. The path I entered was not found. What helped was:
let urlwithExtension = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!.appendingPathComponent("New", isDirectory: false).appendingPathExtension("iink")
let fullpath = urlwithExtension.absoluteString.replacingOccurrences(of: "file://", with: "")
if FileManager.default.fileExists(atPath: fullpath) {
....
}
Thanks Oliver for your response. Do you have a sample of code regarding saving and loading inputs ? I tried to follow your tutorial but get the error "138 a package associated with the filename already exists"
What have I already tried ? Here is a part of my code regarding saving and loading
var part: IINKContentPart!
var package: IINKContentPackage!
var history = [String]()
let packageName = "test.iink"
override viewdidload() {
...
openContent()
...
}
func loadHistory() {
do {
if let history = try part.metadata?.stringArray(forKey: packageName){
self.history = history
}
} catch {
print("Error")
}
}
func saveHistory() {
var parameterSet: IINKParameterSet
parameterSet = part.metadata!
do {
try parameterSet.setStringArray(self.history, forKey: packageName)
part.metadata = parameterSet
} catch {
print("Error")
}
}
func saveContent() {
saveHistory()
do {
try package.save()
} catch {
print("error")
}
}
func openContent() {
if FileManager.default.fileExists(atPath: packageName) {
do {
if let engine = (UIApplication.shared.delegate as? AppDelegate)?.engine {
package = try engine.openPackage(packageName)
part = try package.getPartAt(0)
loadHistory()
}
} catch {
print("Error")
}
} else {
do {
package = try createPackage(packageName: "test")
part = try package.getPartAt(0)
editorViewController.editor.part = part
history = []
} catch {
print("Error while creating package : " + error.localizedDescription)
}
}
}
O
Olivier @MyScript
said
over 5 years ago
Dear Thanh,
currently, when are you getting this error? When opening the package ? Saving it?
When closing your part, are you proceeding as in our code:
Thanh Hoang
Hello again,
I am new into iOS Swift developing, so I do have many questions, sorry. What I want to have is saving only handwritten inputs at the same spots and load them at the same location, not need converted ones. So if I understood correctly, I should follow this page https://developer.myscript.com/docs/interactive-ink/1.3/ios/fundamentals/storage/. Or should I take the "import and export" section ?
If you have answered my question, can I provide some codes to check later ? Since I am new into coding, I have some problems with translating from Objective-C into Swift.
Thanks in advance!
I could solve my problem. The path I entered was not found. What helped was:
- Oldest First
- Popular
- Newest First
Sorted by PopularOlivier @MyScript
Dear Thanh Hoang,
thank you for your question.
Indeed you are right, you shall not use the import/export functions but work with packages (create/save/load) following the link you pointed.
can I provide some codes to check later ?
>>This is out of our scope, we recommend you refer to tutorials for beginners
I have some problems with translating from Objective-C into Swift.
>>We provide our getStarted for the Swift language: https://developer.myscript.com/docs/interactive-ink/1.3/ios/fundamentals/get-started/#playing-with-the-get-started-example
Best regards,
Olivier
Thanh Hoang
Thanks Oliver for your response. Do you have a sample of code regarding saving and loading inputs ? I tried to follow your tutorial but get the error "138 a package associated with the filename already exists"
What have I already tried ? Here is a part of my code regarding saving and loading
Olivier @MyScript
Dear Thanh,
currently, when are you getting this error? When opening the package ? Saving it?
When closing your part, are you proceeding as in our code:
- (void)unloadPart
{
self.currentPackage = nil;
self.editorViewController.editor.part = nil;
self.title = @"";
}
Best regards,
Olivier
Thanh Hoang
I could solve my problem. The path I entered was not found. What helped was:
Olivier @MyScript
Dear Thanh,
thank you for the update, I am glad isse is solved.
Best regards,
Olivier