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);
}
}
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);
}
);
I want to implement image uploading. It works for web (Chrome/Safari), but not for mobile ios (built with Capacitor). It shows image selection, but when I select it nothing happens.
Here is my input:
<q-file
v-model="avatarFile"
accept=".jpg, .png"
#input="uploadImage"
/>
async uploadImage() {
if (this.avatarFile) {
let extension = "jpg";
if (this.avatarFile.type === "image/png") {
extension = "png";
}
try {
this.loading = 1;
const {
data: {
uploadUrl: { uploadUrl },
},
} = await this.$apollo.query({
query: GET_UPLOAD_URL,
variables: {
extension,
},
});
await axios.put(uploadUrl, this.avatarFile);
await setTimeout(() => {
this.$emit("on-image-upload");
this.loading = 0;
}, 3000);
} catch (e) {
this.alertError(e);
this.loading = 0;
}
}
}
What am I doing wrong? Thanx in advance!
Found the solution. My accept rule had the wrong format. This works:
accept="image/*"
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;
}
I have saved all the user's location in the installation object. And i have another object named locationObject which gets updated when the current user sends his current location.When it does, i want to compare his current location with all the other saved locations and send push notifications to the users who are nearby.This is my code but this does not seem to work.
//this code should run when the locationObject is updated
Parse.Cloud.afterSave("locationObject", function (request) {
var geoPoint = request.object.get("myCurrentLocation");
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.near("significantLocationUpdate", geoPoint);
pushQuery.limit(100);
pushQuery.find({
success: function(results) {
if (results.length > 0) {
//console.log(JSON.stringify(results));
for (i = 0; i < results.length; 1++) {
Parse.Push.send({
where: pushQuery,
data: {
alert: "some user is nearby"
}
}, {
success: function() {
console.log("push was successfull")
},
error: function(error) {
console.log("sending push failed")// Handle error
}
});
}
} else {
console.log("failure");
}
},
error: function (error) {
console.log("error");
}
});
});
This is how i restructured the code.And it works. Thanks to Paulw11
Parse.Cloud.afterSave("locationObject", function (request) {
var geoPoint = request.object.get("myCurrentLocation");
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.near("significantLocationUpdate", geoPoint);
pushQuery.limit(100);
Parse.Push.send({
where: pushQuery,
data: {
alert: "some user is nearby"
}
}, {
success: function() {
console.log("push was successful");
},
error: function(error) {
console.log("sending push failed")// Handle error
}
});
});
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"
},