Convert swift to objective c

Could someone convert this to objective c

Thanks!

Getting date of app provisioning profile
func getProvisioningProfileExpirationDate() -> Date?
{
self.getCertificateExpirationDate()
Code Block
let profilePath: String? = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision")
if( profilePath != nil )
{
let plistData = NSData(contentsOfFile: profilePath!)
let plistDataString = String(format: "%@", plistData!)
var plistString: String = extractPlist(fromMobileProvisionDataString:plistDataString)

let pattern = "<key>ExpirationDate</key>.*<date>(.*)</date>"
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let textCheckingResult : NSTextCheckingResult = regex.firstMatch(in: plistString, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSMakeRange(0, plistString.characters.count))!
let matchRange : NSRange = textCheckingResult.range(at: 1)
let expirationDateString : String = (plistString as NSString).substring(with: matchRange)
Code Block
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
print( "Profile expires: \(dateFormatter.date(from: expirationDateString)!)" )

return dateFormatter.date(from: expirationDateString)!
Code Block
}

return nil
}




func extractPlist( fromMobileProvisionDataString:String ) -> String
{
// Remove brackets at beginning and end
var range = Range(NSMakeRange(0, 1), in: fromMobileProvisionDataString)
var plistDataString = fromMobileProvisionDataString.replacingCharacters(in:range!, with: "")
range = Range(NSMakeRange(plistDataString.count-1, 1), in: plistDataString)
plistDataString.replaceSubrange(range!, with: "")
Code Block
// Remove spaces
plistDataString = plistDataString.replacingOccurrences(of: " ", with: "")

// convert hex to ascii
let profileText = hexStringtoAscii( plistDataString )
Code Block
// I tried using regular expressions and normal NSString operations to get this, but it simply wouldn't work, so I went with this ugly method.
// return extractPlistText(fromProfileString:profileText)

// Remove whitespaces and new lines characters and splits into individual lines.
let profileWords = profileText.components(separatedBy: CharacterSet.newlines)
Code Block
var plistString = "";
var inPlist = false;
for word in profileWords
{
if( word.contains("<plist") ) { inPlist = true }

if( inPlist ) { plistString.append(" "); plistString.append( word ) }
Code Block
if (word.contains("</plist")) { inPlist = false }
}
return plistString;
}

func hexStringtoAscii(_ hexString : String) -> String {
Code Block
let pattern = "(0x)?([0-9a-f]{2})"
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let nsString = hexString as NSString
let matches = regex.matches(in: hexString, options: [], range: NSMakeRange(0, nsString.length))
let characters = matches.map {
Character(UnicodeScalar(UInt32(nsString.substring(with: $0.range(at: 2)), radix: 16)!)!)
}
return String(characters)
}
You might have more luck with this if you format your post so that folks can read it. Try putting all of the code in one big code block. You can create a code block using the <> button. Alternatively, you can do this manually by adding a line of triple backticks before and after the code.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Thank you,

Here is the code again as you have mentioned in one block

Code Block language
func getProvisioningProfileExpirationDate() -> Date?
{
self.getCertificateExpirationDate()
let profilePath: String? = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision")
if( profilePath != nil )
{
let plistData = NSData(contentsOfFile: profilePath!)
let plistDataString = String(format: "%@", plistData!)
var plistString: String = extractPlist(fromMobileProvisionDataString:plistDataString)
let pattern = "<key>ExpirationDate</key>.*<date>(.*)</date>"
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let textCheckingResult : NSTextCheckingResult = regex.firstMatch(in: plistString, options: NSRegularExpression.MatchingOptions(rawValue: UInt(0)), range: NSMakeRange(0, plistString.characters.count))!
let matchRange : NSRange = textCheckingResult.range(at: 1)
let expirationDateString : String = (plistString as NSString).substring(with: matchRange)
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
print( "Profile expires: \(dateFormatter.date(from: expirationDateString)!)" )
return dateFormatter.date(from: expirationDateString)!
}
return nil
}
func extractPlist( fromMobileProvisionDataString:String ) -> String
{
// Remove brackets at beginning and end
var range = Range(NSMakeRange(0, 1), in: fromMobileProvisionDataString)
var plistDataString = fromMobileProvisionDataString.replacingCharacters(in:range!, with: "")
range = Range(NSMakeRange(plistDataString.count-1, 1), in: plistDataString)
plistDataString.replaceSubrange(range!, with: "")
// Remove spaces
plistDataString = plistDataString.replacingOccurrences(of: " ", with: "")
// convert hex to ascii
let profileText = hexStringtoAscii( plistDataString )
// I tried using regular expressions and normal NSString operations to get this, but it simply wouldn't work, so I went with this ugly method.
// return extractPlistText(fromProfileString:profileText)
// Remove whitespaces and new lines characters and splits into individual lines.
let profileWords = profileText.components(separatedBy: CharacterSet.newlines)
var plistString = "";
var inPlist = false;
for word in profileWords
{
if( word.contains("<plist") ) { inPlist = true }
if( inPlist ) { plistString.append(" "); plistString.append( word ) }
if (word.contains("</plist")) { inPlist = false }
}
return plistString;
}
func hexStringtoAscii(_ hexString : String) -> String {
let pattern = "(0x)?([0-9a-f]{2})"
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)
let nsString = hexString as NSString
let matches = regex.matches(in: hexString, options: [], range: NSMakeRange(0, nsString.length))
let characters = matches.map {
Character(UnicodeScalar(UInt32(nsString.substring(with: $0.range(at: 2)), radix: 16)!)!)
}
return String(characters)
}
code-block


It seems that you also created a second thread for this, so I’ll respond over there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Convert swift to objective c
 
 
Q