dqhieu / HDPhoneMonitor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HDPhoneMonitor

HDPhoneMonitor is a service allow you to monitor your phone battery level and app memory usage.

preview

Content

Installation

This isn't on CocoaPods yet, so to install, add this to your Podfile

pod 'HDPhoneMonitor', :git => 'https://github.com/dqhieu/HDPhoneMonitor.git'

Usage

Initialize

  1. Import the HDPhoneMonitor module:
import HDPhoneMonitor
  1. Start a HDPhoneMonitor service, typically in your application's application:didFinishLaunchingWithOptions: method:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  // Override point for customization after application launch.
  HDPhoneMonitor.startService()
  return true
}
  1. Enable cloud storage service if you want to save your data on Google Spreadsheet.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  // Override point for customization after application launch.
  HDPhoneMonitor.startService()
  HDPhoneMonitor.enableCloudStorage()
  return true
}

Using

Put HDPhoneMonitor.sharedService.monitor() in the functions that run every 5 mins or less in both background mode and foreground mode. That mean the service will log your phone battery level and memory usage every 5 mins. You can change the time interval in Settings

For example:

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    HDPhoneMonitor.sharedService.monitor()
    // Your code goes here
    ...
}

For periperal devices:

// This function runs every 8 seconds when you set notification for `heartBeatCommandReceiverCharacteristic` and send it a command
func peripheral(peripheral: CBPeripheral, didUpdateNotificationStateForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
    if characteristic.UUID.isEqual(CBUUID(string: BLECharacteristic.HeartBeatSender.rawValue)) {
      HDPhoneMonitor.sharedService.monitor()
      // Your code goes here
      ...
    }
}
func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) {
  HDPhoneMonitor.sharedService.deviceDidConnect(getIdFromDevice(peripheral))
  // Your code goes here
  ...
}
func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
  HDPhoneMonitor.sharedService.deviceConnectionDidDrop(getIdFromDevice(peripheral))
  // Your code goes here
  ...
}

...

Display

Create a UIViewController and set it custom class HDPhoneMonitorChartViewController

Imgur

or create by programmatically

let phoneMonitorChartViewController = HDPhoneMonitorChartViewController()
self.navigationController!.pushViewController(phoneMonitorChartViewController, animated: true)

License

HDPhoneMonitor is released under the MIT license. See LICENSE for details.

SpecialThanks

  • kevinzhow for his awesome PNChart. I did some customizations for better displaying.

About

License:MIT License


Languages

Language:Swift 96.9%Language:Ruby 2.3%Language:Objective-C 0.8%