实际上,我正试图将苹果的示例代码转换为code。
我在devcenter为它创建了一个应用程序和一个APPID。我检查了HealthKit的权限( IAP和GC的权限是灰色的,自动检查)。
当我为它创建的配置配置文件被下载到Xcode中时,我进入Xcode中的首选项,查看我的帐户的配置配置文件,我可以看到配置文件的名称和过期日期,然后有一些权利图标。但是我用HealthKit创建的配置文件没有任何图标,只有2个默认图标,这是正常的:

因为由于某些原因,应用程序在请求授权时崩溃,出现此错误:
2014-10-02 12:16:13.241 SwimFit549:8824 _allowAuthorizationForSharingWithEntitlements::未识别的选择器发送到实例0x107dc1ce0 2014-10-02 12:16:13.251 SwimFit549:8824 *由于不明异常“NSInvalidArgumentException”,原因:-_NSCFConstantString _allowAuthorizationForSharingWithEntitlements::未识别的选择器发送到实例0x107dc1ce0‘
如果我试图在设备上运行它,我会得到以下信息:

我创造了:
这次我做的唯一奇怪的事情是,当我点击build/运行某个点的时候,我让Xcode创建了一个AppID,我从devcenter获得了这个.我不能上传图像,但基本上我以前所有的应用程序都是以这个应用程序命名的。这是因为它由xcode制造,名为: Xcode,iOS,App,com,santiapp,SwimFit,但是它的包标识符在: com.santiapps.SwimFit上是正确的。开发配置文件也是如此: iOS Team : com.santiapps.SwimFit及其在构建设置中的配置文件。最初,我使用了SwimFit,因为这是应用程序的名称,所以Xcode为它创建了一个自动AppID,并为它创建了一个ProvProfile。然后,我想也许我应该创建appID和provprofile,所以我手动地做了,并尝试将它命名为SwimFit2。两人都犯了同样的错误。
我还能错过什么?
以下是代码:
//1. Add healthstore property
var healthStore: HKHealthStore? //error if not optionally unwrapped
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//2. Ask for permissions
if (HKHealthStore.isHealthDataAvailable() == true) {
self.healthStore = HKHealthStore() //needs to be var for it to work?
var writeDataTypes = self.dataTypesToWrite()
var readDataTypes = self.dataTypesToRead()
self.healthStore!.requestAuthorizationToShareTypes(writeDataTypes, readTypes: readDataTypes, completion: { (success: Bool, error: NSError!) -> Void in
if (!success) {
NSLog("You didn't allow HealthKit to access these read/write data types. In your app, try to handle this error gracefully when a user decides not to provide access. The error was: %@. If you're using a simulator, try it on a device.", error)
return
} else {
NSLog("success")
}
// Handle success in your app here.
self.setupHealthStoreForTabBarControllers()
})
}
return true
}下面是一个屏幕截图的链接:http://youtu.be/BBagkNTpfQA
发布于 2014-11-04 04:05:03
我昨天也发生了同样的车祸。问题是,将数据类型的数据类型(NSString)放入方法中是错误的。
requestAuthorizationToShareTypes方法要求您传递一组HKBaseType对象,在我的例子中是对象。
因此,与其:
[_healthStore requestAuthorizationToShareTypes:[NSSet setWithObject:HKQuantityTypeIdentifierBodyMassIndex]
readTypes:[NSSet setWithArray:inputDataTypes]
completion:用这个:
HKQuantityType* type = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex];
[_healthStore requestAuthorizationToShareTypes:[NSSet setWithObject:type]
readTypes:[NSSet setWithArray:inputDataTypes]
completion:https://stackoverflow.com/questions/26167182
复制相似问题