@@ -270,7 +270,7 @@ - (void)checkProvisioning:(NSTimer *)timer {
270
270
if (identifierOK) {
271
271
NSLog (@" Provisioning completed." );
272
272
[statusLabel setStringValue: @" Provisioning completed" ];
273
- [self doCodeSigning ];
273
+ [self doEntitlementsFixing ];
274
274
} else {
275
275
[self showAlertOfKind: NSCriticalAlertStyle WithTitle: @" Error" AndMessage: @" Product identifiers don't match" ];
276
276
[self enableControls ];
@@ -287,6 +287,69 @@ - (void)checkProvisioning:(NSTimer *)timer {
287
287
}
288
288
}
289
289
290
+ - (void )doEntitlementsFixing
291
+ {
292
+ if (![entitlementField.stringValue isEqualToString: @" " ] || [provisioningPathField.stringValue isEqualToString: @" " ]) {
293
+ [self doCodeSigning ];
294
+ return ; // Using a pre-made entitlements file or we're not re-provisioning.
295
+ }
296
+
297
+ [statusLabel setStringValue: @" Generating entitlements" ];
298
+
299
+ if (appPath) {
300
+ generateEntitlementsTask = [[NSTask alloc ] init ];
301
+ [generateEntitlementsTask setLaunchPath: @" /usr/bin/security" ];
302
+ [generateEntitlementsTask setArguments: @[@" cms" , @" -D" , @" -i" , provisioningPathField.stringValue]];
303
+ [generateEntitlementsTask setCurrentDirectoryPath: workingPath];
304
+
305
+ [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector (checkEntitlementsFix: ) userInfo: nil repeats: TRUE ];
306
+
307
+ NSPipe *pipe=[NSPipe pipe ];
308
+ [generateEntitlementsTask setStandardOutput: pipe];
309
+ [generateEntitlementsTask setStandardError: pipe];
310
+ NSFileHandle *handle = [pipe fileHandleForReading ];
311
+
312
+ [generateEntitlementsTask launch ];
313
+
314
+ [NSThread detachNewThreadSelector: @selector (watchEntitlements: )
315
+ toTarget: self withObject: handle];
316
+ }
317
+ }
318
+
319
+ - (void )watchEntitlements : (NSFileHandle *)streamHandle {
320
+ @autoreleasepool {
321
+ entitlementsResult = [[NSString alloc ] initWithData: [streamHandle readDataToEndOfFile ] encoding: NSASCIIStringEncoding];
322
+ }
323
+ }
324
+
325
+ - (void )checkEntitlementsFix : (NSTimer *)timer {
326
+ if ([generateEntitlementsTask isRunning ] == 0 ) {
327
+ [timer invalidate ];
328
+ generateEntitlementsTask = nil ;
329
+ NSLog (@" Entitlements fixed done" );
330
+ [statusLabel setStringValue: @" Entitlements generated" ];
331
+ [self doEntitlementsEdit ];
332
+ }
333
+ }
334
+
335
+ - (void )doEntitlementsEdit
336
+ {
337
+ NSDictionary * entitlements = entitlementsResult.propertyList ;
338
+ entitlements = entitlements[@" Entitlements" ];
339
+ NSString * filePath = [workingPath stringByAppendingPathComponent: @" entitlements.plist" ];
340
+ NSData *xmlData = [NSPropertyListSerialization dataWithPropertyList: entitlements format: NSPropertyListXMLFormat_v1_0 options: kCFPropertyListImmutable error: nil ];
341
+ if (![xmlData writeToFile: filePath atomically: YES ]) {
342
+ NSLog (@" Error writing entitlements file." );
343
+ [self showAlertOfKind: NSCriticalAlertStyle WithTitle: @" Error" AndMessage: @" Failed entitlements generation" ];
344
+ [self enableControls ];
345
+ [statusLabel setStringValue: @" Ready" ];
346
+ }
347
+ else {
348
+ entitlementField.stringValue = filePath;
349
+ [self doCodeSigning ];
350
+ }
351
+ }
352
+
290
353
- (void )doCodeSigning {
291
354
appPath = nil ;
292
355
0 commit comments