I had a similar problem in my application where we needed to take steps only for the Apple iPhone and Apple Watch. I searched a lot, but could not find an answer to it for iOS 8.0 and landed on your question.
I figured out a way to distinguish between a watch and a phone using the following process (maybe not the best solution, but it works in my situation):
, , iPhone/Watch, bundleIdentifier:
com.apple.health.DeviceUUID
, "" com.apple.Health( "H" ).
, -, , :
NSString *deviceName = [[UIDevice currentDevice] name];
, "com.apple.health" bundleIdentifier. iPhone Apple .
, (iPhone), Apple Watch.
:
- (void)fetchSources
{
NSString *deviceName = [[UIDevice currentDevice] name];
NSMutableArray *dataSources = [[NSMutableArray alloc] init];
HKQuantityType *stepsCount = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKSourceQuery *sourceQuery = [[HKSourceQuery alloc] initWithSampleType:stepsCount
samplePredicate:nil
completionHandler:^(HKSourceQuery *query, NSSet *sources, NSError *error)
{
for (HKSource *source in sources)
{
if ([source.bundleIdentifier hasPrefix:sourceIdentifier] && ![source.name isEqualToString:deviceName])
{
[dataSources addObject:source];
}
}
}];
[self.healthStore executeQuery:sourceQuery];
}
NSPredicate:
NSPredicate *sourcesPredicate = [HKQuery predicateForObjectsFromSource:source];
, , UUID, UUID NSUUID, , .
, , , "".
, , , , . , , . .