Is my payload malformed to call didReceiveRemoteNotification in background? - php

According to these (and many more) questions on SO:
stackoverflow.com/questions/18856204
stackoverflow.com/questions/20741618
stackoverflow.com/questions/31967093
stackoverflow.com/questions/19068762
stackoverflow.com/questions/30936507
I figured out, that the main keys for silent push-notification and for the method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
to be called in the background are: the payload, iOS version > iOS 7, enabled background mode with "Remote notifications" and registering push notifications in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.
I did all of those things, but the method mentioned above, that supposed to be called in the background, is only being called while the app is foreground. This is how I form my payload in php:
$contents = json_encode(array(
'aps' => array(
'content-available' => '1',
'sound' => '',
'alert' => '',
),
'where' => array(
'deviceType' => array(
'$in' => array('ios', 'android'),
),
),
'data' => array(
'title' => $this->subject,
'msg' => $this->message,
'date' => date('d.m.Y H:i', time() + (60 * 60 * 2)),
'key' => APPKEY,
'ids' => $ids,
),
));
and this is what I get in Xcode console, as I am able to NSLog the payload when app is in foreground:
{
aps = {
};
date = "21.10.2015 11:01";
ids = (
259,
257,
256,
);
key = xpy3fq4t3wn9;
msg = test11;
title = aatest1;
}
What am I doing wrong? Why isnt "content-available = 1" in Xcode console? Or is there any other reason why appDelegate method isnt being called in background?
Im using iOS 8.1.3, Parse as Push-Notification provider.

I was able to solve my problem just by trying different payload combinations, ended up with this one:
$contents = json_encode(array(
'where' => array(
'deviceType' => array(
'$in' => array('ios', 'android'),
),
),
'data' => array(
'title' => $this->subject,
'msg' => $this->message,
'date' => date('d.m.Y H:i', time() + (60 * 60 * 2)),
'key' => APPKEY,
'ids' => $ids,
'aps' => array(
'content-available' => '1',
'sound' => '',
'alert' => '',
),
),
));
Looks like 'aps' has to be in 'data' array. Now the app delegate method is being called in background and I can see "content-available = 1" in Xcode console.

Related

Invalid parameter Facebook Lead Leadgen Form in Facebook Marketing API

I am getting error from Facebook Marketing API when creating Leadgen Form. I followed Facebook guide but nothing worked yet. API documentation link
In previous I was successfully create leadgen legal content, leadgen context cards, leadgen conditional questions group and conditional questions group csv. After that I am trying to create Leadgen Form but API returns Invalid parameter
$config = Config::get('facebook');
$data['account_id'] = 'act_'.$config['ad_account_id'];
$data['page_id'] = $config['page_id'];
$api = Api::init($config['app_id'], $config['app_secret'], $config['access_token']);
// Init facebook
$legal_params = array(
'privacy_policy' => array(
'url' => 'http://example.com/privacy-policy',
'link_text' => 'Privacy Policy'
),
'custom_disclaimer' => array(
'title' => 'Terms and Conditions',
'body' => array(
'text' => 'My custom disclaimer',
'url_entities' => array(
array("offset" => 3, "length" => 6, "url" => 'http://example.com/privacy-policy')
),
),
'checkboxes' => array(array(
"is_required" => false,
"is_checked_by_default" => false,
"text" => "Allow to contact you",
"key" => "checkbox_1",
))
),
);
$legal_res = Api::instance()->call('/'.$data['page_id'].'/leadgen_legal_content',
RequestInterface::METHOD_POST,
$legal_params)->getContent();
$legal_content_id = $legal_res['id'];
$contex_params = array(
'title' => 'Thank You',
'style' => 'LIST_STYLE',
'content' => array(
'Easy sign-up flow',
'Submit your info to have a chance to win',
),
'button_text' => 'Get started',
);
$contex_res = Api::instance()->call('/'.$data['page_id'].'/leadgen_context_cards',
RequestInterface::METHOD_POST,
$contex_params)->getContent();
$context_card_id = $contex_res['id'];
// Conditional Questions
$conditional_request = Api::instance()->prepareRequest(
'/'.$data['page_id'].'/leadgen_conditional_questions_group',
RequestInterface::METHOD_POST);
$conditional_request->getFileParams()->offsetSet(
'conditional_questions_group_csv',
(new FileParameter(public_path().'/facebook/lead-csv-form.csv'))->setMimeType("text/csv"));
$csv_data = Api::instance()->executeRequest($conditional_request)->getContent();
$questions_group_id = $csv_data['id'];
// Create Lead Form
$form = new LeadgenForm(null, $data['page_id']);
$form->setData(array(
LeadgenFormFields::NAME => 'Test LeadAds Form Name',
LeadgenFormFields::FOLLOW_UP_ACTION_URL => 'https://www.facebook.com/examplepage',
LeadgenFormFields::QUESTIONS => array(
(new LeadGenQuestion())->setData(array(
LeadgenQuestionFields::TYPE => 'EMAIL',
)),
(new LeadGenQuestion())->setData(array(
LeadgenQuestionFields::TYPE => 'CUSTOM',
LeadgenQuestionFields::LABEL => 'Country',
'conditional_questions_group_id' => $questions_group_id,
'dependent_conditional_questions' => array(
array('name' => 'State'),
array('name' => 'City'),
)
)),
),
'block_display_for_non_targeted_viewer' => true,
'context_card_id' => $context_card_id,
'legal_content_id' => $legal_content_id,
));
$form->create();

aws SDK 3, PHP, runInstance does not create the supplied Tags

$options = array(
'UserData' => base64_encode('test'),
'SecurityGroupIds' => [AWS_REGIONS[$region]['security_group']],
'InstanceType' => AWS_REGIONS[$region]['instance_type'],
'ImageId' => AWS_REGIONS[$region]['ami'],
'MaxCount' => $to_launch,
'MinCount' => 1,
//'EbsOptimized' => true,
'SubnetId' => AWS_REGIONS[$region]['subnet_id'],
'Tags' => [['Key' => 'task', 'Value' => $task],['Key' => 'Name', 'Value' => $task]],
'InstanceInitiatedShutdownBehavior' => 'terminate'
);
$response = $client->runInstances($options);
I am using the "latest" Ec2Client
It launches fine but the Tags are completely ignored.
I suspect an error within the EC2 API but I am not that experienced.
Maybe someone with experience can help me out ?
This is because Ec2Client::runInstances does not have tags option
http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-10-01.html#runinstances
You would need to make a separate call to tag newly created instance(s) using Ec2Client::createTags:
$result = $client->createTags(array(
'DryRun' => true || false,
// Resources is required
'Resources' => array('string', ... ),
// Tags is required
'Tags' => array(
array(
'Key' => 'string',
'Value' => 'string',
),
// ... repeated
),
));
Read more here:
http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-10-01.html#createtags

Laravel $push->getAdapter()->getResponse() is blank for iphone

I am using Laravel push notification library, for pushing notification.
However, i can easly get responses for GCM responses for Android Device.
But unable to get APNS response.
$message = PushNotification::Message("New Messages",$params['payload']);
$collection = PushNotification::app('appNameIOS')
->to($params['reg_id'])
->send($message);
foreach ($collection->pushManager as $push) {
$response = $push->getAdapter()->getResponse();
}
Make sure you have followed proper format as below:-
//iOS app
PushNotification::app(['environment' => 'development',
'certificate' => '/path/to/certificate.pem',
'passPhrase' => 'password',
'service' => 'apns']);
$devices = PushNotification::DeviceCollection(array(
PushNotification::Device('token', array('badge' => 5)),
PushNotification::Device('token1', array('badge' => 1)),
PushNotification::Device('token2')
));
$message = PushNotification::Message('Message Text',array(
'badge' => 1,
'sound' => 'example.aiff',
'actionLocKey' => 'Action button title!',
'locKey' => 'localized key',
'locArgs' => array(
'localized args',
'localized args',
),
'launchImage' => 'image.jpg',
'custom' => array('custom data' => array(
'we' => 'want', 'send to app'
))
));
$collection = PushNotification::app('appNameIOS')
->to($devices)
->send($message);
// get response for each device push
foreach ($collection->pushManager as $push) {
$response = $push->getAdapter()->getResponse();
}

Hipay payment Gateway integration Response in php

I'm using a hipay wallet test account and used there webservices to integrate. Transaction is working fine but problem is that i'm not getting the response in the page, it is suppossed to get in $_POST['xml'] on the response page
$setUrlAck =show_page_link("payment/hipay_new/response.php",true);
Below is my code
if ($PaymentDetails['sel_payment_env'] == 1) {
$wsdl = 'https://ws.hipay.com/soap/subscription?wsdl'; //for live
} else {
$wsdl = 'https://test-ws.hipay.com/soap/subscription?wsdl';//for testing
}
// If the payment is accepted, the user will be redirected to this page
$setURLOk= show_page_link(FILE_THANKS."?add=success&OrderNo=".$orderid,true);
// If the payment is refused, the user will be redirected to this page
$setUrlNok=show_page_link(FILE_THANKS."?cancleMsg=true",true);
// If the user cancels the payment, he will be redirected to this page
$setUrlCancel=show_page_link(FILE_THANKS."?cancleMsg=true",true);
// The merchant?s site will be notified of the result of the payment by a call to the script
$setUrlAck =show_page_link("payment/hipay_new/response.php",true);
$initArray = array(
'wsLogin' => $wsLogin, // Your wsLogin
'wsPassword' => $wspassword, // Your wsPassword
'websiteId' => $txt_Merchant, // Your webSiteId
'categoryId' => $PaymentDetails['txt_category_id'], // Your website category ID (https://test-payment.hipay.com/order/list-categories/id/(websiteId))
'customerEmail' => $customer_email, // Your customers' email
);
$options = array(
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'cache_wsdl' => WSDL_CACHE_NONE,
);
$client = new SoapClient($wsdl, $options);
$data = array(
'currency' => $currency_code,
'rating' => 'ALL',
'locale' => 'fr_FR',
'manualCapture' =>1,
'label' => 'My label is a Manged Subscrption Test Service ',
'customerIpAddress' => $_SERVER["REMOTE_ADDR"],
'merchantReference' => 'AZERTY',
'urlCallback' => $setUrlAck, // Here in this page i'm suppossed to get the response in $_POST
'urlAccept' => $setURLOk,
'urlCancel' =>$setUrlCancel,
'payments' => array(
'initial' => array(
'name' => 'Payment',
'description' => 'Payment for printing products',
'amount' => $price,
'subscriptionId' => 'QWERTY',
'periodType' => 'normal',
'recurrence' => array(
'frequency' => 0,
'duration' => 'managed'
),
),
),
);
Kindly guide me if anyone got through the same issues
The issue is solved, problem was that my firewall setting was blocking the response

AWS PHP SDK issue with Dynamodb WriteRequestBatch

I am experimenting with WriteRequestBatch from AWS SDK for Dynamodb. Below is my code. Everything works except the WriteRequestBatch part. I have no clue why, and was wondering if the community could help me out here. What might I be doing wrong? I have tried googling and searching here and found only 8 other questions that could be related but unfortunately were of no help.
This is where I started from.
$ddb_client = DynamoDbClient::factory(array(
'region' => 'us-east-1',
'key' => 'my_key',
'secret' => 'my_secret'
));
$ddb_client->createTable(array(
'TableName' => 'my_table',
'AttributeDefinitions' => array(
array(
'AttributeName' => 'id',
'AttributeType' => 'S'
),
array(
'AttributeName' => 'ns',
'AttributeType' => 'S'
)
),
'KeySchema' => array(
array(
'AttributeName' => 'id',
'KeyType' => 'HASH'
),
array(
'AttributeName' => 'ns',
'KeyType' => 'RANGE'
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 10
)
));
$response = $ddb_client->putItem(array(
"TableName" => "my_table",
"Item" => array(
"id" => array("S" => "exp_id"),
"ns" => array("S" => "exp_ns"),
"version" => array("N" => "0"),
),
));
$item = $response['Item'];
$item['version']['N'] = '1';
$put_batch = WriteRequestBatch::factory($ddb_client);
$put_request = new PutRequest(
array(
"Item" => $item,
"Expected" => array(
"version" => array(
"ComparisonOperator" => "EQ",
"AttributeValueList" => array(
array("N" => "0")
)
),
),
),
"my_table"
);
$putBatch->add($put_request);
$putBatch->flush();
This works instead of WriteRequestBatch. I will just have to manage batches to put myself than use WriteRequestBatch doing it for me:
$response = $ddb_client->batchWriteItem(array(
"RequestItems" => array(
"my_table" => array(
array(
"PutRequest" => array(
"Item" => $item,
"Expected" => array(
"version" => array(
"ComparisonOperator" => "EQ",
"AttributeValueList" => array(
array("S" => "0")
)
),
),
)
)
)
)
));
The answer by Geek Stocks is incomplete, but still helpful. One thing you can do handle the asynchronous aspects of the CreateTable operation is to use a Waiter:
$ddb_client->createTable(array('TableName' => 'my_table', ... ));
$ddb_client->waitUntil('TableExists', array('TableName' => 'my_table'));
However, there is also a problem with how you are using the WriteRequestBatch class. When you create a PutRequest, you must pass in the item, not a whole set of PutItem parameters. The WriteRequestBatch is an abstraction over DynamoDB's BatchWriteItem operation, which does not allow things like the Expected parameter. If you want to do that, then you need to use individual PutItem/UpdateItem/DeleteItem requests.
Here is a modified version of your usage of WriteRequestBatch that is correct:
$putBatch = WriteRequestBatch::factory($ddb_client);
$putBatch->add(new PutRequest($item, 'my_table'));
// ADD MORE...
// ...
// ...
$putBatch->flush();
Here is another example of using the WriteRequestBatch from the SDK's User Guide.
EDIT: One more complete example that works that I just tested, that shows the difference between versions prior to 2.7.0 and afterwards
use Aws\DynamoDb\DynamoDbClient;
use Aws\DynamoDb\Model\BatchRequest\WriteRequestBatch;
use Aws\DynamoDb\Model\BatchRequest\PutRequest;
use Aws\DynamoDb\Model\Item;
$client = DynamoDbClient::factory([/* ... */]);
$batch = WriteRequestBatch::factory($client);
for ($i = 1; $i <= 55; $i++) {
// FOR ANY SDK VERSION
// (NOTE: Does not support new M, L, BOOL, and NULL types)
$item = Item::fromArray(['id' => $i, 'data' => "foo{$i}"]);
// FOR SDK >= 2.7
$item = ['id' => ['N' => $i], 'data' => ['S' => "foo{$i}"]];
$batch->add(new PutRequest($item, 'my-table'));
}
$batch->flush();
Because you currently do not have any "try / catch" error handling around your code you are likely not getting good information on your error.
I placed try/catch blocks on your code and found that the table creates just fine but that the call to putItem fails for the following reason: Requested resource not found
When you create a table it is NOT immediately available. You have to pause until it becomes available. This paragraph of the AWS docs explains this nicely:
CreateTable is an asynchronous operation. Upon receiving a CreateTable request, DynamoDB immediately returns a response with a TableStatus of CREATING . After the table is created, DynamoDB sets the TableStatus to ACTIVE . You can perform read and write operations only on an ACTIVE table. You can use the DescribeTable API to check the table status.
Once you add the call to DescribeTable like it shows, you should be good.

Categories