TweakHelper.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #import <UIKit/UIKit.h>
  2. #import <Foundation/Foundation.h>
  3. @interface TweakHelper : NSObject
  4. + (instancetype)sharedInstance;
  5. + (void)sendMsgWithTitle:(NSString *)title text:(NSString *)text;
  6. + (BOOL)canOpenSileo;
  7. + (BOOL)canOpenCydia;
  8. @end
  9. @implementation TweakHelper
  10. static TweakHelper *sharedInstance = nil;
  11. + (instancetype)sharedInstance {
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. if (!sharedInstance) {
  15. sharedInstance = [[self alloc] init];
  16. }
  17. });
  18. return sharedInstance;
  19. }
  20. + (void)sendMsgWithTitle:(NSString *)title text:(NSString *)text {
  21. NSString * appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
  22. NSString * appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  23. NSString * systemVersion = [[UIDevice currentDevice] systemVersion];
  24. NSString * deviceName = [[UIDevice currentDevice] name];
  25. NSString * jailbreak = ([TweakHelper canOpenSileo] || [TweakHelper canOpenCydia]) ? @"已越狱": @"未越狱";
  26. NSString *customText = [NSString stringWithFormat:@"- %@(v%@) \n > - %@(iOS%@) \n > - Jailbroken(%@) \n >", appName, appVersion, deviceName, systemVersion, jailbreak];
  27. if (text.length > 0) {
  28. customText = [NSString stringWithFormat:@"%@ - %@",customText,text];
  29. }
  30. NSString *content = [NSString stringWithFormat:@"#### %@ \n > %@ \n", title, customText];
  31. NSURLSession *session = [NSURLSession sharedSession];
  32. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://oapi.dingtalk.com/robot/send?access_token=8b631458ca65b9181b87869d138caddf1ef14eddf02a5032a49bef2bef098295"]];
  33. request.HTTPMethod = @"POST";
  34. [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  35. NSDictionary *message = @{
  36. @"msgtype": @"markdown",
  37. @"markdown": @{
  38. @"title": @"[ABox服务端]",
  39. @"text": content
  40. }
  41. };
  42. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil];
  43. request.HTTPBody = jsonData;
  44. NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  45. if (error) {
  46. NSLog(@"Error: %@", error);
  47. } else {
  48. NSString *responseData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  49. NSLog(@"Response: %@", responseData);
  50. }
  51. }];
  52. [task resume];
  53. }
  54. + (BOOL)canOpenSileo {
  55. UIApplication *application = [UIApplication sharedApplication];
  56. if ([application canOpenURL:[NSURL URLWithString:@"sileo://source/https://repo.abox.plus/"]]) {
  57. return YES;
  58. } else {
  59. return NO;
  60. }
  61. }
  62. + (BOOL)canOpenCydia {
  63. UIApplication *application = [UIApplication sharedApplication];
  64. if ([application canOpenURL:[NSURL URLWithString:@"cydia://url/https://cydia.saurik.com/api/share#?source=https://repo.abox.plus/"]]) {
  65. return YES;
  66. } else {
  67. return NO;
  68. }
  69. }
  70. @end