0% found this document useful (0 votes)
52 views4 pages

Uiviewcontroller Uiimageview Nsstring

This document contains code for an iOS app written in Swift that uses Alamofire and SwiftyJSON to make API requests to Instagram and download a user's profile image. It defines a ViewController class with methods to make the API requests, parse the response, and display the image in an image view. When a button is tapped, it downloads the profile image URL from Instagram and makes a second request to actually download the image data and display it.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

Uiviewcontroller Uiimageview Nsstring

This document contains code for an iOS app written in Swift that uses Alamofire and SwiftyJSON to make API requests to Instagram and download a user's profile image. It defines a ViewController class with methods to make the API requests, parse the response, and display the image in an image view. When a button is tapped, it downloads the profile image URL from Instagram and makes a second request to actually download the image data and display it.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

import UIKit

import Alamofire
import SwiftyJSON
import SwiftSoup

class ViewController: UIViewController {

let searchstr = "profilePage_"


@IBOutlet var imageView: UIImageView!
var get_List_URL: NSString?

override func viewDidLoad()


{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
@IBAction func GetImage(_ sender: Any)
{
f()
}
func f()
{
self.view.makeToast("Downloading..", duration:
1.0, position: .bottom)
let get_List_URLs =
"https://www.instagram.com/sidc"

Alamofire.request(get_List_URLs).responseString(qu
eue: DispatchQueue.global(qos: .utility), encoding:
String.Encoding.utf8, completionHandler: { response
in
//print(response.value!)
let AllStr : String = response.value!
let result = AllStr.range(of: self.searchstr,
options:
NSString.CompareOptions.literal,
range:
AllStr.startIndex..<AllStr.endIndex,
locale: nil)

// See if string was found.


if let range = result {
let start = range.lowerBound
let getStr =
AllStr[start..<AllStr.endIndex]
let endOfSentence = getStr.index(of:
"\"")!
let firstSentence =
getStr[...endOfSentence]

let name =
firstSentence.replacingOccurrences(of:
self.searchstr, with: "")
let NameStringiD =
name.replacingOccurrences(of: "\"", with: "")
self.get_List_URL =
"https://i.instagram.com/api/v1/users/\
(NameStringiD)/info" as NSString

DispatchQueue.main.async(execute: {
self.Classic(name: self.get_List_URL!
as String)
})

}
else
{
print("String not present")
}
})
}
func Classic(name : String)
{
Alamofire.request(name, method: .post,
parameters: nil, encoding: JSONEncoding.default,
headers: nil).responseJSON
{ (response:DataResponse) in
switch(response.result) {
case .success(_):

if let jsonValue = response.result.value {


let json = JSON(jsonValue)

if((response.result.value) != nil)
{

DispatchQueue.main.async(execute: {
let categories_name =
json["user"]["hd_profile_pic_url_info"]
["url"].stringValue
print(categories_name)
})
}
}
break
case .failure(_):
print("Please check your internet
connection")
break
}
}

UIApplication.shared.isNetworkActivityIndicatorVisibl
e = false
}
}

You might also like