2015-08-26 33 views
0

我有一個非常快速的初學者問題:我怎樣才能讓這個功能共享一個URL呢?我總是遵循一切,並認爲我是對的,但它似乎不工作......非常感謝!分享網址連同截圖和文字

func takeSnapshot(view: UIView) { 
    let bounds = UIScreen.mainScreen().bounds 
    UIGraphicsBeginImageContextWithOptions(bounds.size, true, 0.0) 
    self.view.drawViewHierarchyInRect(bounds, afterScreenUpdates: false) 
    let image = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 
    let text = "Text to be shared... #Hashtag" 
    let activityViewController = UIActivityViewController(activityItems: [image, text], applicationActivities: nil) 
    self.presentViewController(activityViewController, animated: true, completion: nil) 

回答

0

只需添加一個NSURL

let bounds = UIScreen.mainScreen().bounds 
UIGraphicsBeginImageContextWithOptions(bounds.size, true, 0.0) 
self.view.drawViewHierarchyInRect(bounds, afterScreenUpdates: false) 
let image = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext() 
let text = "Text to be shared... #Hashtag" 
let URL = NSURL(string: "http://stackoverflow.com/")! 

let activityViewController = UIActivityViewController(activityItems: [image, text, URL], applicationActivities: nil) 
self.presentViewController(activityViewController, animated: true, completion: nil) 
+0

我剛開始一個小細節錯了...謝謝你這麼多! –