I'm trying to validate an Apple IAP auto-renewing receipt (https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html), but the response payload seems to be (surprisingly) empty. I would greatly appreciate if you could point me in the right direction.
Here is the javascript implementation via Parse CloudCode:
Parse.Cloud.define('validateReceipt', function (request, response) {
// params:
// debugMode
// userObjectId
// receiptData
var storeURL = null;
if (request.params.debugMode) {
storeURL = 'https://sandbox.itunes.apple.com/verifyReceipt';
} else {
storeURL = 'http://buy.itunes.apple.com/verifyReceipt';
}
var receiptAsBase64EncodedString = request.params.receiptData;
var postData = {
method: 'POST',
url: storeURL,
headers: { 'Content-Type': 'application/json' },
body: { 'receipt-data': receiptAsBase64EncodedString,
'password': 'SHARED_SECRET' }
}
Parse.Cloud.httpRequest(postData).then(function (httpResponse) {
var expirationDate = httpResponse.data.latest_receipt.expiration_date;
var userQuery = new Parse.Query('_User');
userQuery.get(request.params.userObjectId, {
success: function(user) {
user.set('subscriptionExpirationDate', expirationDate);
user.save(null, {
success: function(thread) {
return response.success('Subscription Active');
},
error: function(user, error) {
console.error('Error saving subscriptionExpirationDate for User: ' + error.code + ' - ' + error.message);
return response.error('Error saving subscriptionExpirationDate for User: ' + error.code + ' - ' + error.message);
}
});
},
error: function(object, error) {
console.error('Error fetching User: ' + error.code + ' - ' + error.message);
return response.error('Error saving subscriptionExpirationDate for User: ' + error.code + ' - ' + error.message);
}
});
});
});
If I print httpResponse.data to the console, the output is:
No Message provided
However, if I implement the same logic from my client in obj-C, I have the expected result:
NSError *error;
NSDictionary *requestContents = #{
#"receipt-data": [receiptData base64EncodedStringWithOptions:0],
#"password": #"SHARED_SECRET"
};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:0
error:&error];
NSURL *storeURL = [NSURL URLWithString:#"https://sandbox.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:#"POST"];
[storeRequest setHTTPBody:requestData];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (!connectionError) {
NSError *error;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
}
}];
Printing jsonReponse:
{
environment = Sandbox;
"latest_receipt" = "...";
"latest_receipt_info" = (
{
"expires_date" = "2015-10-09 02:11:19 Etc/GMT";
[...]
},
status = 0;
}
Related
I'm using react-native-fbsdk {ShareDialog} to post my feeds on Facebook but ShareDialog is not returning the post Id it's always null in my case.
My Import
import { ShareDialog, LoginManager, AccessToken, LoginButton } from "react-native-fbsdk";
This is my code
const shareLinkContent = {
contentType: 'link',
contentUrl: 'https://www.niofox.com/',
contentDescription: 'Test Sharing Description'
};
var tmp = this;
ShareDialog.canShow(shareLinkContent).then(
(canShow) => {
if (canShow) {
return ShareDialog.show(shareLinkContent);
}
}
).then(
(result) => {
if (result.isCancelled) {
alert('Share cancelled');
} else {
alert('Share success with postId: ' + JSON.stringify(result));
}
},
(error) => {
alert('Share fail with error: ' + error);
}
);
using parse dashboard in local system, implemented cloud functions and getting an error when call cloud function
main.js:
Parse.Cloud.define('cloudFunctions', function (req, res) {
const query = new Parse.Query("Test");
if (req.params.Name) {
query.equalTo('Name', req.params.Name);
}
query.find()
.then((results) => {
var testArray = new Array();
for (let i = 0; i < results.length; i++) {
testArray[i] = {
id: results[i].id,
Name: results[i].get("Name"),
Description: results[i].get("Description")
};
}
var obj={
result:testArray
}
res.success(obj);
}, (error) => {
res.success("Save failed! " + error);
});
});
client side:
var gettestparams = {
Name: ""
}
Parse.Cloud.run('cloudFunctions', gettestparams).then(function (callback) {
console.log("get test call", callback);
}).catch((error) => {
console.log("fail", error);
});
I am creating an app, in which supremenewyork.com website is loaded in WKWebView. But when the website is loaded I do not want to load images in it. How can I do this in Objective-C.
I have following which prevent to load images of website in WKWebView. I have used content blocker rules which are documented official web site of Apple. Check here. Creating a Content Blocker.
- (void)viewDidLoad {
[super viewDidLoad];
// id blockRules = #" [{ \"trigger\": { \"url-filter\": \".*\", \"resource-type\": [\"image\"] }, \"action\": { \"type\": \"block\" } }, { \"trigger\": { \"url-filter\": \".*\", \"resource-type\": [\"style-sheet\"] }, \"action\": { \"type\": \"block\" } }, { \"trigger\": { \"url-filter\": \".*.jpeg\" }, \"action\": { \"type\": \"ignore-previous-rules\" } }] ";
id blockRules = #" [{ \"trigger\": { \"url-filter\": \".*\", \"resource-type\": [\"image\"] }, \"action\": { \"type\": \"block\" } }] ";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"https://www.supremenewyork.com/"]];
[[WKContentRuleListStore defaultStore] compileContentRuleListForIdentifier: #"ContentBlockingRules" encodedContentRuleList:blockRules completionHandler:^(WKContentRuleList *contentRuleList, NSError *error) {
if (error != nil) {
NSLog(#"Error = %#", error.localizedDescription);
}
else {
WKWebViewConfiguration *configuration = self.webView.configuration;
[[configuration userContentController] addContentRuleList:contentRuleList];
dispatch_async(dispatch_get_main_queue(), ^{
[self.webView loadRequest:request];
});
}
}];
}
Output:
1.
Output:
2.
This is Swift version based on Mayur Karmur's answer:
let blockRules = "[{ \"trigger\": { \"url-filter\": \".*\", \"resource-type\": [\"image\"] }, \"action\": { \"type\": \"block\" } }]";
WKContentRuleListStore.default().compileContentRuleList(forIdentifier: "ContentBlockingRules", encodedContentRuleList: blockRules) {
contentRuleList, error in
if let error = error {
print("Error =", error.localizedDescription);
}else if let contentRuleList = contentRuleList{
let configuration = self.webView.configuration;
configuration.userContentController.add(contentRuleList);
}
}
I'm now got stuck that I cannot retrieve how to fetch value from below json of Google Place Detail API.
I want to get all data from "types" node.
{
"address_components" = (
{
"long_name" = "Bridge Street";
"short_name" = "Bridge St";
types = (
route
);
},
{
"long_name" = London;
"short_name" = London;
types = (
locality,
political
);
},
{
"long_name" = London;
"short_name" = London;
types = (
"postal_town"
);
},
{
"long_name" = "Greater London";
"short_name" = "Greater London";
types = (
"administrative_area_level_2",
political
);
},
{
"long_name" = "United Kingdom";
"short_name" = GB;
types = (
country,
political
);
},
{
"long_name" = "SW1A 2LW";
"short_name" = "SW1A 2LW";
types = (
"postal_code"
);
}
);
vicinity = London;
}
Why not integrate Google places API itself rather than parsing yourself.
It's simple and easy to retrieve places
here is the link
https://developers.google.com/places/ios-api/
You can use google places api. Use place id and use below code to get place details value.
-(id)getAddressFromPlaceId:(NSString*)placeId
{
NSString *placeRequest;
if ([AppDelegate getInstance].isDetailsLimitReached)
{
placeRequest = [[NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/details/json?placeid=%#&key=%#&language=en",placeId,[Utility getInstance].arrGooglkey[tempc]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
else
{
placeRequest = [[NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/details/json?placeid=%#&language=en",placeId] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:placeRequest]cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
NSError *error;
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
if (error)
{
return nil;
}
else
{
NSDictionary *resData = [NSJSONSerialization JSONObjectWithData:response options:0 error:&error];
if (error)
{
return nil;
}
else
{
if ([resData[#"status"] isEqualToString:#"OK"] || [[resData objectForKey:#"status"] isEqualToString:#"ZERO_RESULTS"]) {
return [resData[#"result"] mutableCopy];
}
else
{
if ([AppDelegate getInstance].isDetailsLimitReached)
{
return nil;
}
[AppDelegate getInstance].isDetailsLimitReached = TRUE;
return [self getAddressFromPlaceId:placeId];
}
}
}
return nil;
}
I'm trying to implement the "Checking Duplicate Username" first of all, I have to get my json which stored all the record of my users. and get the object which is the username. Then matching them with the text from the UItTextField. My problem is that I can see all my json but I can't seems to parse it correctly.
-(IBAction) ChkUsername: (id) sender {
NSDictionary * userdata = [NSDictionary new];
[DIOSUser userGet: userdata success: ^ (AFHTTPRequestOperation * operation, id response) {
NSLog(#"%#", response);
DIOSSession * session = [DIOSSession sharedSession];
[session setUser: [response objectForKey: #"user"]];
NSDictionary * uname = [
[session user] objectForKey: #"name"];
if ([self.txtUsernameRegister.text isEqualToString: uname]) {
// if([uname isEqual:self.txtUsernameRegister.text]){
NSLog(#"You cannot use this Username");
} else {
NSLog(#"You can use this username");
}
}
failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {
NSLog(#"%#", [error localizedDescription]);
}];
}
I also got this error NSCFArray objectForKey:]
Edit here is how my JSON looks like.
{
uid: "60",
name: "pae1344",
mail: "viper1344#gmail.com",
theme: "",
signature: "",
signature_format: "plain_text",
created: "1396189622",
access: "0",
login: "1396189622",
status: "1",
timezone: "Asia/Bangkok",
language: "",
picture: "0",
init: "viper1344#gmail.com",
data: null,
uri: "http://localhost/drupal/rest/user/60"
},