आप
"<key>ExpirationDate</key><date>2014-12-06T00:26:10Z</date>" in [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]
की तरह कुछ के लिए देख रहे हैं लेकिन हो रही वहाँ आसान नहीं है! इस कोड में सुधार किया जा सकता है, इसके कुछ हिस्सों अन्य stackoverflow पदों पर आधारित थे। नोट: एक और विकल्प आइटम प्लिस्ट और/plist ... के बीच सबकुछ लोड करना होगा ... एक प्लेस्ट (शब्दकोश)। लेकिन चूंकि हम पहले से ही वहां हैं, हम सिर्फ हाथ से भाई पा रहे हैं।
- (NSString*) getExpiry{
NSString *profilePath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"];
// Check provisioning profile existence
if (profilePath)
{
// Get hex representation
NSData *profileData = [NSData dataWithContentsOfFile:profilePath];
NSString *profileString = [NSString stringWithFormat:@"%@", profileData];
// Remove brackets at beginning and end
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@""];
profileString = [profileString stringByReplacingCharactersInRange:NSMakeRange(profileString.length - 1, 1) withString:@""];
// Remove spaces
profileString = [profileString stringByReplacingOccurrencesOfString:@" " withString:@""];
// Convert hex values to readable characters
NSMutableString *profileText = [NSMutableString new];
for (int i = 0; i < profileString.length; i += 2)
{
NSString *hexChar = [profileString substringWithRange:NSMakeRange(i, 2)];
int value = 0;
sscanf([hexChar cStringUsingEncoding:NSASCIIStringEncoding], "%x", &value);
[profileText appendFormat:@"%c", (char)value];
}
// Remove whitespaces and new lines characters
NSArray *profileWords = [profileText componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//There must be a better word to search through this as a structure! Need 'date' sibling to <key>ExpirationDate</key>, or use regex
BOOL sibling = false;
for (NSString* word in profileWords){
if ([word isEqualToString:@"<key>ExpirationDate</key>"]){
NSLog(@"Got to the key, now need the date!");
sibling = true;
}
if (sibling && ([word rangeOfString:@"<date>"].location != NSNotFound)) {
NSLog(@"Found it, you win!");
NSLog(@"Expires: %@",word);
return word;
}
}
}
return @"";
}
स्रोत
2014-01-08 20:56:36
प्रोफाइल के लिए इसकी वापसी शून्य पहली पंक्ति पर ही है। मैं xcode 8.2.1 का उपयोग कर रहा हूं और इस उद्देश्य-सी कोड का उपयोग तेजी से कर रहा हूं। – Skywalker
क्या आप सिम्युलेटर में कोड चला रहे हैं? यह हस्ताक्षरित नहीं है, इसलिए सिम्युलेटर पर चलने पर कोई एम्बेडेड.मोबाइलप्रोविजन फ़ाइल नहीं होगी। भौतिक डिवाइस पर कोड चलाने का प्रयास करें (कोड पर हस्ताक्षर किए जाने चाहिए और एम्बेडेड.मोबाइलप्रोविजन फ़ाइल को सिद्धांत रूप में वहां होना चाहिए। – wottle