2014-09-24 50 views
1

我是IOS的新手,我將Instagram集成到我的應用程序中。iOS處理打開的網址swift

@IBOutlet weak var WebView: UIWebView! 


    var UrlInsta = "https://instagram.com/oauth/authorize/?client_id=my_id&redirect_uri=Locations://test&response_type=code"; 

func loadInstaSite(){ 
     let requestURL = NSURL(string: UrlInsta); 
     let requestSite = NSURLRequest(URL: requestURL); 

     WebView.loadRequest(requestSite); 

     NSLog("%d" , 1); 

    } 

這是我ViewController.swift 的WebView打開罰款。 當用戶點擊授權我的應用程序並轉到地點://測試,我的應用程序再次打開我的主視圖web view。 如何處理我的應用程序打開時的網址?

回答

1
let url = "http://apple.com" 

變化viewDidLoad方法來

override func viewDidLoad() { 
    super.viewDidLoad() 

    let requestURL = NSURL(string:url) 
    let request = NSURLRequest(URL: requestURL) 
    webView.loadRequest(request) 
    } 

Here is an example with source code

您還可以通過蘋果

試試這個代碼會向委託打開由URL標識的資源。 宣言

Swift 

optional func application(_ application: UIApplication, 
        openURL url: NSURL, 
     sourceApplication sourceApplication: String, 
       annotation annotation: AnyObject?) -> Bool 

Objective-C 

- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation 

Here is the more explanation