使用Python/Kivy为iOS/iPhone环境。
应用程序本身运行良好,Python/Kivy->toolchain.py->XCode->iPhone操作。
我希望通过iCloud为多个平台共享应用程序数据,因此希望将数据写入iCloud文档存储。我可以做好使用iCloud的所有准备(绑定标识符、AppID、供应配置文件,并成功地激活了XCode上的iCloud和iCloud文档)。然后,我在互联网上没有找到示例代码,也没有找到如何使用Python/Kivy将数据写入iCloud文档存储或将数据从存储复制到iCloud文档存储的书籍。也许,如果我可以使用Python/Kivy使函数等价于以下SWIFT代码,我就能够解决这个问题。
let manager = NSFileManager()
let manager.copyItemAtPath(srcPath, toPath: toPath, error: nil)
有没有办法使用Python/Kivy将数据写入iCloud或将数据从用户存储复制到iCloud存储?下面是一个示例代码,我想添加这样的函数。
from kivy.app import App
import os
import pickle
setting_in = {'parameter1': 'abcde', 'parameter2': 'fghij'}
setting_out = {}
def readsetting(read_settingfilename):
setting1 = {}
if os.path.exists(read_settingfilename):
try:
with open(read_settingfilename, 'rb') as f1:
try:
setting1 = pickle.load(f1)
except pickle.UnpicklingError:
print('Read error!')
else:
print('********** File' + read_settingfilename + 'was read!! **********')
except IOError:
print('File' + read_settingfilename + 'could not be opened for reading')
else:
pass
return setting1
def writesetting(write_settingfilename, setting1):
try:
with open(write_settingfilename, 'wb') as f:
try:
pickle.dump(setting1,f)
except pickle.PicklingError:
print('File output error!')
outputflag = 1
else:
print('********** File created!! **********')
outputflag = 0
except IOError:
print('File' + write_settingfilename + 'could not be opened for writing')
outputflag = 1
return outputflag
DATAPATH = App().user_data_dir + 'test/'
if os.path.isdir(DATAPATH) == False:
os.mkdir(DATAPATH)
datafilename = 'test.dat'
writesetting(DATAPATH + datafilename, setting_in)
setting_out = readsetting(DATAPATH + datafilename)
print(setting_out)