2015-10-05 52 views
0

我正在执行此功能来保存启用和禁用iCloud的UIDocument,但我似乎错过了两次投掷。特别是当iCloud存储过程saveToURL返回false时,我不知道它为什么如此,因为文档不是零,路径是合理的;这是我的功能简介:UIDocument中的saveToURL返回false

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 
} 

感谢您的支持。

回答

0

我甚至有可能用苹果票丢票之后最终抛弃了UIDocument,并决定将字典保存为正常的NSUserDefault。