Skip to content

Commit

Permalink
fixed multiplatform uikit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TheM4hd1 committed Dec 5, 2020
1 parent 684098f commit 36d2835
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 33 deletions.
10 changes: 10 additions & 0 deletions SwiftyInsta.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@
E8A611E925458D4D003EAF16 /* SwCrypt.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8A611E725458D4D003EAF16 /* SwCrypt.swift */; };
E8A611EA25458D4D003EAF16 /* SwCrypt.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8A611E725458D4D003EAF16 /* SwCrypt.swift */; };
E8A611EB25458D4D003EAF16 /* SwCrypt.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8A611E725458D4D003EAF16 /* SwCrypt.swift */; };
E8C58ED5257B907C007327A8 /* UserAgentHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8C58ED4257B907C007327A8 /* UserAgentHelper.swift */; };
E8C58ED6257B907C007327A8 /* UserAgentHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8C58ED4257B907C007327A8 /* UserAgentHelper.swift */; };
E8C58ED7257B907C007327A8 /* UserAgentHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8C58ED4257B907C007327A8 /* UserAgentHelper.swift */; };
E8C58ED8257B907C007327A8 /* UserAgentHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8C58ED4257B907C007327A8 /* UserAgentHelper.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -304,6 +308,7 @@
E0F8D51B22F9E4CF0004309C /* SupportedCapabilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportedCapabilities.swift; sourceTree = "<group>"; };
E805D294254ADD4F006E536B /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
E8A611E725458D4D003EAF16 /* SwCrypt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwCrypt.swift; sourceTree = "<group>"; };
E8C58ED4257B907C007327A8 /* UserAgentHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserAgentHelper.swift; sourceTree = "<group>"; };
E9497D8DD2D1B4C4F52B1DC5 /* Pods-SwiftyInsta.iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftyInsta.iOS.release.xcconfig"; path = "Target Support Files/Pods-SwiftyInsta.iOS/Pods-SwiftyInsta.iOS.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -410,6 +415,7 @@
1104CD0A2180627400F855BA /* Error.swift */,
110B3F9A21A2CE4D0019523A /* Extensions.swift */,
E805D294254ADD4F006E536B /* Utilities.swift */,
E8C58ED4257B907C007327A8 /* UserAgentHelper.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -883,6 +889,7 @@
11C106CF218DE9B20014D0E5 /* PaginationParameters.swift in Sources */,
E0628FCC22FDEAA2007E3BEE /* Authentication.swift in Sources */,
1104CD0B2180627400F855BA /* Error.swift in Sources */,
E8C58ED5257B907C007327A8 /* UserAgentHelper.swift in Sources */,
E0628FD122FDEF10007E3BEE /* Credentials.swift in Sources */,
E007B1B622F8207F00750E6D /* CommentResponse.swift in Sources */,
E0F49BA122E49E34004C3E7F /* FeedHandler.swift in Sources */,
Expand Down Expand Up @@ -941,6 +948,7 @@
E004434C2345E4D2000497DF /* Endpoint.swift in Sources */,
E006E43622E87EFE002DB4BB /* Extensions.swift in Sources */,
E006E41322E87EFE002DB4BB /* PaginationParameters.swift in Sources */,
E8C58ED6257B907C007327A8 /* UserAgentHelper.swift in Sources */,
E0D0EF1B22F8EBBB00CBFE36 /* UploadResponse.swift in Sources */,
E0337968233118AE00C176FC /* (null) in Sources */,
E006E3F022E87EFE002DB4BB /* CommentHandler.swift in Sources */,
Expand Down Expand Up @@ -999,6 +1007,7 @@
E004434D2345E4D2000497DF /* Endpoint.swift in Sources */,
E006E48322E87EFF002DB4BB /* Extensions.swift in Sources */,
E006E46022E87EFF002DB4BB /* PaginationParameters.swift in Sources */,
E8C58ED7257B907C007327A8 /* UserAgentHelper.swift in Sources */,
E0D0EF1C22F8EBBB00CBFE36 /* UploadResponse.swift in Sources */,
E0337969233118AE00C176FC /* (null) in Sources */,
E006E43D22E87EFF002DB4BB /* CommentHandler.swift in Sources */,
Expand Down Expand Up @@ -1057,6 +1066,7 @@
E004434E2345E4D2000497DF /* Endpoint.swift in Sources */,
E006E4D022E87F00002DB4BB /* Extensions.swift in Sources */,
E006E4AD22E87F00002DB4BB /* PaginationParameters.swift in Sources */,
E8C58ED8257B907C007327A8 /* UserAgentHelper.swift in Sources */,
E0D0EF1D22F8EBBB00CBFE36 /* UploadResponse.swift in Sources */,
E033796A233118AF00C176FC /* (null) in Sources */,
E006E48A22E87F00002DB4BB /* CommentHandler.swift in Sources */,
Expand Down
37 changes: 4 additions & 33 deletions SwiftyInsta/API/Constants/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import UIKit

struct Constants {
private init() {}
Expand All @@ -25,9 +24,7 @@ struct Constants {
static let xIgAppId = "X-IG-App-ID"
static let xIgAppIdValue = "124024574287414"
static let userAgentKey = "User-Agent"
// swiftlint:disable line_length
static let userAgentValue = "Instagram 160.1.0.31.120 (\(getIdentifier()); iOS \(getOsVersion()); en_US; en-US; scale=2.00; \(getScreenSize()); 246979827) AppleWebKit/420+"
// swiftlint:enable line_length
static let userAgentValue = getUserAgent()
static let contentTypeKey = "Content-Type"
static let contentTypeApplicationFormValue = "application/x-www-form-urlencoded"
static let igSignatureKey = "signed_body"
Expand All @@ -41,37 +38,11 @@ struct Constants {
static let rankTokenKey = "rank_token"
static let bloksVersioningId = "7b2216598d8fcf84fbda65652788cb12be5aa024c4ea5e03deeb2b81a383c9e0"

static func getIdentifier() -> String {
#if os(iOS) && !((arch(i386)) || arch(x86_64))
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce(into: "") { (identifier, element) in
if let value = element.value as? Int8, value != 0 {
identifier += String(UnicodeScalar(UInt8(value)))
}
}
return identifier
#else
return "iPhone9,1"
#endif
}

static func getOsVersion() -> String {
#if os(iOS)
return UIDevice.current.systemVersion.replacingOccurrences(of: ".", with: "_")
#else
return "13_5"
#endif
}

static func getScreenSize(scale: CGFloat = 2.0) -> String {
static func getUserAgent() -> String {
#if os(iOS)
let width = Int(UIScreen.main.bounds.width * scale)
let height = Int(UIScreen.main.bounds.height * scale)
return String(format: "%dx%d", arguments: [width, height])
return UserAgentHelper.generate()
#else
return "750x1334"
return "Instagram 160.1.0.31.120 iPhone9,1; iOS 13_5; en_US; en-US; scale=2.00; 750x1334; 246979827) AppleWebKit/420+"
#endif
}
}
46 changes: 46 additions & 0 deletions SwiftyInsta/Helpers/UserAgentHelper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// UserAgentHelper.swift
// SwiftyInsta
//
// Created by Mahdi Makhdumi on 12/5/20.
// Copyright © 2020 Mahdi. All rights reserved.
//

#if os(iOS)
import UIKit

struct UserAgentHelper {
static func generate() -> String {
// swiftlint:disable line_length
return "Instagram 160.1.0.31.120 (\(getIdentifier()); iOS \(getOsVersion()); en_US; en-US; scale=2.00; \(getScreenSize()); 246979827) AppleWebKit/420+"
// swiftlint:enable line_length
}

fileprivate static func getIdentifier() -> String {
#if !((arch(i386)) || arch(x86_64))
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce(into: "") { (identifier, element) in
if let value = element.value as? Int8, value != 0 {
identifier += String(UnicodeScalar(UInt8(value)))
}
}
return identifier
#else
return "iPhone9,1"
#endif
}

fileprivate static func getOsVersion() -> String {
return UIDevice.current.systemVersion.replacingOccurrences(of: ".", with: "_")
}

fileprivate static func getScreenSize(scale: CGFloat = 2.0) -> String {
let width = Int(UIScreen.main.bounds.width * scale)
let height = Int(UIScreen.main.bounds.height * scale)
return String(format: "%dx%d", arguments: [width, height])
}
}

#endif

0 comments on commit 36d2835

Please sign in to comment.