main.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from time import sleep
  2. from pymobiledevice3.lockdown import create_using_usbmux
  3. from pymobiledevice3.services.dvt.instruments.process_control import ProcessControl
  4. from pymobiledevice3.services.installation_proxy import InstallationProxyService
  5. from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService
  6. DD_BUNDLE_ID = 'com.laiwang.DingTalk' # 钉钉包名
  7. WDA_BUNDLE_ID = 'com.caner.test.xctrunner' #个人包名
  8. # 启动app
  9. def launchApp(lockdown,installer,BUNDLE_ID,Name):
  10. if(BUNDLE_ID and lockdown and installer):
  11. Apps = [app for app in installer.get_apps() if Name in app]
  12. if len(Apps):
  13. if Apps[0] == BUNDLE_ID:
  14. with DvtSecureSocketProxyService(lockdown) as dvt:
  15. process_control = ProcessControl(dvt)
  16. pid = process_control.launch(BUNDLE_ID)
  17. print("启动app",pid,BUNDLE_ID)
  18. sleep(3)
  19. return True
  20. else:
  21. return False
  22. else:
  23. return False
  24. else:
  25. return False
  26. def main():
  27. try:
  28. # 连接手机
  29. lockdown = create_using_usbmux()
  30. # 获取已安装的app
  31. with InstallationProxyService(lockdown) as installer:
  32. # 启动WDA
  33. wda_start = launchApp(lockdown,installer,WDA_BUNDLE_ID,'xctrunner')
  34. if(wda_start):
  35. print('已启动wda')
  36. # 启动钉钉
  37. dd_start = launchApp(lockdown,installer,DD_BUNDLE_ID,'DingTalk')
  38. if(dd_start):
  39. print('已启动钉钉')
  40. else:
  41. print("没找到钉钉安装包")
  42. else:
  43. print("没找到WDA安装包")
  44. except ConnectionError as e:
  45. print("连接失败")
  46. if __name__ == '__main__':
  47. main()