【问题标题】:saveToURL in UIDocument returns falseUIDocument 中的 saveToURL 返回 false
【发布时间】:2016-01-02 14:51:11
【问题描述】:

我正在执行此函数以保存启用和禁用 iCloud 的 UIDocument,但我似乎错过了两次抛出。特别是当iCloud被启用时,saveToURL返回false,我不知道为什么会这样,因为文档不是nil并且路径是合理的;这是我的简要功能:

func newFavorite(favorite: palinaModel) ->Bool {
    if indexForPalina(favorite) != nil {
        print("stop already favorite")
        return false;
    }
// Save Stop
    let baseURL = NSFileManager.defaultManager().URLForUbiquityContainerIdentifier(nil)
    var favoriteURL:NSURL!
    if (baseURL != nil) {
        let favoritesURL = baseURL!.URLByAppendingPathComponent(pathComponent())
        favoriteURL = favoritesURL.URLByAppendingPathComponent(String(format:"Stop_%@", favorite.palina))
    } else {
        let filePath = getFilePath()
        favoriteURL=NSURL(fileURLWithPath: filePath)
    }
    let document = FavoriteStopDocument(fileURL:favoriteURL, favorite:favorite)

// Add Bookmark To Bookmarks
    self.favoriteElements.append(document)
    print("favoriteUrl=" + favoriteURL.path!+" document="+document.favoriteStop!.palina)
    document.saveToURL(favoriteURL, forSaveOperation:.ForCreating, completionHandler:{(success) in
        if (success) {
            print("Save succeeded.");
        } else {
            print("Save failed.");
        }
    })

    return true
}

感谢您的支持。

【问题讨论】:

    标签: swift icloud uidocument


    【解决方案1】:

    我什至可能浪费了与 Apple 的票后,最终放弃了 UIDocument,并决定将字典保存为普通的 NSUserDefault。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多