私のアプリは復元購入後にサーバーに領収書を送信します。 To辞書には、「bundleId」(アプリバンドルID)、「UUID」(アプリIDForVendor)の2つの追加キーが追加されます。 承認され、最初に実行された後、アプリケーションのすべてが正常です(すべてのキーを取得した後に復元した後)。ユーザーがアプリケーションを削除して再インストールすると、これらのキーにはnull値が設定されます。parson jsonの後のヌル値
現在appStoreReceiptを取得:
if(!self.receiptData){
NSURL *receiptURL = [[NSBundle mainBundle]
appStoreReceiptURL];
self.receiptData = [NSData
dataWithContentsOfURL:receiptURL]
receipt = [self.receiptData bkrBase64EncodedString];
}
else{
receipt = [self.receiptData bkrBase64EncodedString];
}
アップルの要求:
if(receipt){
NSError *error;
NSDictionary *requestContents = @{
@"receipt-data" : receipt,
@"password" : //purchaseAppSecreatKey
};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:0
error:&error];
if (!requestData) { /* ... Handle error ... */
}
// Create a POST request with the receipt data.
NSURL *storeURL = ///iTunesVerificationURL
NSMutableURLRequest *storeRequest =
[NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];
// Make a connection to the iTunes Store on a background queue.
NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
[NSURLConnection
sendAsynchronousRequest:storeRequest
queue:operationQueue
completionHandler:^(NSURLResponse *response, NSData *data,
NSError *connectionError) {
if (connectionError) {
NSLog(@"response error %@", connectionError.localizedDescription);
} else {
NSError *error;
NSDictionary *jsonResponse =
[NSJSONSerialization JSONObjectWithData:data
options:0
error:&error] ;
if(!error){
//success, sending to server
}else{
NSLog(@"parse error %@", error.localizedDescription);
}
}
}];
}
NSMutableDictionary *requestBodyDictonary = [NSMutableDictionary dictionaryWithDictionary:reciptDic];
[requestBodyDictonary setObject:[self bundleId] forKey:@"bundleId"];
[requestBodyDictonary setObject:[self UUID] forKey:@"uuid"];
NSURL *url = [NSURL URLWithString:];
NSError *error = nil;
NSData *bodyData = [NSJSONSerialization dataWithJSONObject:requestBodyDictonary options:0 error:&error];
if(error == nil){
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:15.0];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:bodyData];
NSURLSession *defaultstSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionDataTask *task = [defaultstSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"complete %ld", (long)[(NSHTTPURLResponse *)response statusCode]);
}];
[task resume];
}else{
NSLog(@"error parshe %@", [error localizedDescription]);
}
にサーバーコードにフェッチUUIDを送信し、
#pragma mark - User ID
-(NSString *)UUID{
if(!_UUID){
_UUID = [[NSUserDefaults standardUserDefaults] stringForKey:@"identifierForVendor_UUID"];
if(!_UUID){
_UUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[[NSUserDefaults standardUserDefaults]setObject:_UUID forKey:@"identifierForVendor_UUID"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
}
return _UUID;
}
#pragma mark bundle id
-(NSString *)bundleId{
if(!_bundleId){
_bundleId = [[NSUserDefaults standardUserDefaults] stringForKey:@"app_BundleId"];
if(!_bundleId){
_bundleId = [[NSBundle mainBundle]bundleIdentifier];
if(!_bundleId){
_bundleId = (__bridge_transfer NSString *)CFDictionaryGetValue(CFBundleGetInfoDictionary(CFBundleGetMainBundle()),
(const void *)(@"CFBundleIdentifier"));
}
[[NSUserDefaults standardUserDefaults] setObject:_bundleId forKey:@"app_BundleId"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
return _bundleId;
}
をbundleid
なぜ私のアプリは再インストール後にnullを返しますか? サンドボックスモードですべてOKです
ヌルを返すものは何ですか? NSUserDefaultsに関連している場合は、再インストール後に完全に削除されたことを知っている必要があります。 –
@IulianOnofrei私はそれを知っていますが、もしNSUserDefaultsからの値がnilなら、私はもう一度フェッチして、それをNSUserDefaultsに格納します。最初のバージョンのアプリケーションではNSUserDefaultsを使用していませんが、まだnullがあります – quba88