Good mood
To add a package dependency to your Xcode project, Select Project -> Select Package Dependencies -> Click on plus button (lower left corner)
In the next window search following url https://github.com/tilakkap/iOSIntegrity
and click Add Package
Select iOSIntegrity and click Add Package
Add a .swift
file to your project, and name it IntegrityCheck.swift
.
In IntegrityCheck.swift
:
import Foundation
import iOSIntegrity
public class IntegrityCheck: NSObject {
@objc static func check() -> Bool {
let checkSum = iOSIntegrity.checkBundleCheckSum()
return checkSum
}
}
In AppDelegate.m:
#import "<#YourProjectName#>-Swift.h"
The file:<#YourProjectName#>-Swift.h
should already be created automatically in your project, even if you can not see it.
before
[self.window makeKeyAndVisible];
//integrity
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"integrity start");
bool ic = [IntegrityCheck check];
if(ic == false) {
dispatch_sync(dispatch_get_main_queue(), ^{
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"INTEGRITY" message:@"Something went wrong" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK",@"confirm") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// continue your work
exit(1);
}]];
[self.window.rootViewController presentViewController:alert animated:YES completion: nil];
});
}
});
Select xcodeproj file of you project -> Select Target -> Select Build Phases -> Click on plus button (upper left corner) -> Select New Run Script Phase.
Xcode will add a empty script
Put following code in the script window
cd ${BUILD_DIR%Build/*}SourcePackages/checkouts/iOSIntegrity
SDKROOT=macosx
swift run -c release iOSIntegrityCli $METAL_LIBRARY_OUTPUT_DIR
Run following commands
sudo arch -x86_64 gem install ffi
cd ios/ && arch -x86_64 pod install
If you faced following build errors
Select your project in Xcode, and go to "Build Settings". Scroll down until you see "Search Paths", and finally, "Library Search Paths"
Replace $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)
with $(SDKROOT)/usr/lib/swift
.