2

I have a WebView app in my iPhone but I want when I click in share button in google+ and Facebook I would like to open it in Facebook app *when installed,when not in safari )but another links to open all in web view just from Facebook and google+ \ import UIKit

class ViewController: UIViewController {

@IBOutlet weak var webView: UIWebView!





static let LOAD_FROM_URL = true






override func viewDidLoad() {
    super.viewDidLoad()


    if ViewController.LOAD_FROM_URL {
        // URLからロードする
        if let requestURL = NSURL(string: "http://google.com/") {  // TODO: URLを指定する
            let req = NSURLRequest(URL: requestURL)
            self.webView.loadRequest(req)
        }

    }

}






func WebView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    // [SDK] 広告クリックの時の処理を行う
    if !WebView(webView, shouldStartLoadWithRequest: request, navigationType: navigationType) {
        return false;
    }
    return true;
 }
}
Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
Ton Tonii
  • 61
  • 8

1 Answers1

1

SOLUTION:

Have a look at this: How to open fb and instagram app by tapping on button in Swift

1st links on Google. Or are you looking for something different ?


EDIT: You asked me how to make the button trigger an event, here' how:

1) Open the Assistant editor by using ALT-CMD-ENTER.

2) Create an IBAction from your button by CTRL dragging from the button to your code:

3) Put the necessary code in your IBAction, for example:

@IBAction func Fb(sender: UIButton) {

        if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
            let fbShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)

            self.presentViewController(fbShare, animated: true, completion: nil)

        } else {
            let alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)

            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
            self.presentViewController(alert, animated: true, completion: nil)
        }
    }
Community
  • 1
  • 1
Coder1000
  • 4,071
  • 9
  • 35
  • 84