我正在編寫一個Cocoa應用程序,我想從使用Scripting Bridge的應用程序生成一個Numbers電子表格。我生成了Numbers.h文件,並按照Apple's Documentation中的說明鏈接了ScriptingBridge.framework。下面是我用來試圖簡單地創建Numbers文檔並保存它的代碼。如何使用objective-c創建Numbers電子表格?
NSString *path = @"/Users/username/Desktop/Test.numbers";
NumbersApplication *numbers = [SBApplication applicationWithBundleIdentifier:@"com.apple.iWork.Numbers"];
[numbers activate];
NumbersDocument *document = [[[numbers classForScriptingClass:@"document"] alloc] initWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:project.title, @"name", nil]];
[[numbers documents] addObject:document];
[document saveAs:nil in:[NSURL URLWithString:path]];
的代碼可以編譯和運行,當我嘗試另存爲:在:方法我收到以下錯誤:
- [SBProxyByClass的saveAs:在:]:對象沒有被添加到一個容器還;選擇器未識別[self = 0x2005912e0]
除了將文檔添加到[numbers documents]數組之外,還有其他事項我必須做嗎?
我打算使用AppleScript,但如果可以的話,我寧願使用腳本橋。