app_callback.mm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // app_callback.mm
  3. // WFChatClient
  4. //
  5. // Created by heavyrain on 2017/11/5.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #include "app_callback.h"
  9. #include <mars/comm/autobuffer.h>
  10. #import <UIKit/UIKit.h>
  11. #import "WFCCUtilities.h"
  12. #import "sys/utsname.h"
  13. #import "WFCCNetworkService.h"
  14. #import <CoreTelephony/CTCarrier.h>
  15. #import <CoreTelephony/CTTelephonyNetworkInfo.h>
  16. namespace mars {
  17. namespace app {
  18. AppCallBack* AppCallBack::instance_ = NULL;
  19. AppCallBack* AppCallBack::Instance() {
  20. if(instance_ == NULL) {
  21. instance_ = new AppCallBack();
  22. }
  23. return instance_;
  24. }
  25. void AppCallBack::Release() {
  26. delete instance_;
  27. instance_ = NULL;
  28. }
  29. AppCallBack::AppCallBack() {
  30. }
  31. void AppCallBack::SetAccountUserName(const std::string &userName) {
  32. info.username = userName;
  33. NSString *path = [WFCCUtilities getDocumentPathWithComponent:[NSString stringWithUTF8String:info.username.c_str()]];
  34. filePath = [path UTF8String];
  35. }
  36. void AppCallBack::SetAccountLogoned(bool isLogoned) {
  37. info.is_logoned = isLogoned;
  38. }
  39. // return your app path
  40. std::string AppCallBack::GetAppFilePath(){
  41. return filePath;
  42. }
  43. AccountInfo AppCallBack::GetAccountInfo() {
  44. return info;
  45. }
  46. unsigned int AppCallBack::GetClientVersion() {
  47. return 0;
  48. }
  49. static BOOL PSPDFIsDevelopmentBuild() {
  50. #if TARGET_IPHONE_SIMULATOR
  51. return YES;
  52. #else
  53. static BOOL isDevelopment = NO;
  54. static dispatch_once_t onceToken;
  55. dispatch_once(&onceToken, ^{
  56. // There is no provisioning profile in AppStore Apps.
  57. NSData *data = [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]];
  58. if (data) {
  59. const char *bytes = (const char *)[data bytes];
  60. NSMutableString *profile = [[NSMutableString alloc] initWithCapacity:data.length];
  61. for (NSUInteger i = 0; i < data.length; i++) {
  62. [profile appendFormat:@"%c", bytes[i]];
  63. }
  64. // Look for debug value, if detected we're a development build.
  65. NSString *cleared = [[profile componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet] componentsJoinedByString:@""];
  66. isDevelopment = [cleared rangeOfString:@"<key>get-task-allow</key><true/>"].length > 0;
  67. }
  68. });
  69. return isDevelopment;
  70. #endif
  71. }
  72. int AppCallBack::GetPushType() {
  73. return PSPDFIsDevelopmentBuild() ? 1 : 0;
  74. }
  75. DeviceInfo AppCallBack::GetDeviceInfo() {
  76. DeviceInfo info;
  77. struct utsname systemInfo;
  78. uname(&systemInfo);
  79. NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
  80. info.clientid = [[UIDevice currentDevice].identifierForVendor.UUIDString cStringUsingEncoding:NSUTF8StringEncoding];
  81. info.platform = PlatformType_iOS;
  82. info.packagename = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"] UTF8String];
  83. info.pushtype = mars::app::AppCallBack::Instance()->GetPushType();
  84. info.device = [deviceString UTF8String];
  85. info.deviceversion = [[UIDevice currentDevice].systemVersion UTF8String];
  86. info.phonename = [[UIDevice currentDevice].name UTF8String];
  87. NSArray *languages = [NSLocale preferredLanguages];
  88. NSString *currentLanguage = [languages objectAtIndex:0];
  89. info.language = [currentLanguage UTF8String];
  90. CTTelephonyNetworkInfo *nwinfo = [[CTTelephonyNetworkInfo alloc] init];
  91. CTCarrier *carrier = nwinfo.subscriberCellularProvider;
  92. info.carriername = carrier.carrierName ? [carrier.carrierName UTF8String] : "";
  93. info.appversion = [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] UTF8String];
  94. info.sdkversion = [SDKVERSION UTF8String];
  95. return info;
  96. }
  97. }}