Archive
Under the Crypt: My first Mac OSX game !
Just this morning, we finally had our app “Under the crypt” accepted by Apple. It’s available for $0.99 cents and is available for Mountain Lion (64 Bit) or higher. It was designed with Xamarin – a .NET based cross platform app development system, – it is a port of a Phonegap app, that was previously available for Blackberry and Android on the Amazon app store. Thanks goes to to @veubeke, @UlrikeErdmann, and Tyber Zann for programming support!
Download here; https://itunes.apple.com/us/app/under-the-crypt/id1013484922?ls=1&mt=12
Send email via #Amazon SES via PHP using #PHPMailer
<?php
require_once(‘scripts/phpmailer/PHPMailerAutoload.php’);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = “tls”;
$mail->Host = “email-smtp.eu-west-1.amazonaws.com”;
$mail->Port = 587;
$mail->Username = “xxxx”;
$mail->Password = “xxxx”;
$mail->CharSet = ‘windows-1250’;
$mail->SetFrom (‘info@domain.com’, ‘info@domain.com’);
$mail->Subject = “Subject line “;
$mail->ContentType = ‘text/plain’;
$mail->IsHTML(false);
$mail->Body = “this is the body”;
$mail->AddAddress (‘someone@gmail.com’, ‘Someone’);
if(!$mail->Send())
{
$error_message = “Mailer Error: ” . $mail->ErrorInfo;
} else
{
$error_message = “Successfully sent!”;
}
echo $error_message;
?>
Get details of a WebException in C=
If a HTTP call fails with a HTTP 500 error, and throws a WebException, you know something’s gone wrong, but sometimes the response from the server can explain more about what screwed up. I found myself writing this code over and over again, so here’s a single method that handles it;
private static string GetExceptionDetails(WebException exception)
{
string strResult = “”;
if (exception.Response != null)
{
var responseStream = exception.Response.GetResponseStream();
if (responseStream != null)
{
using (var reader = new StreamReader(responseStream))
{
strResult = reader.ReadToEnd();
}
}
}
return strResult;
}
Hope this helps solve your web related problems!
Print an Image using #Xamarin.mac
Printing an image using Xamarin turned out to be much easier than I thought, I loaded the image from a URL into an NSImageCell using;
string strUrl = “http;// Some Url with an image“; // ?
NSUrl url = new NSUrl (strUrl);
this.imgCell.Image = new NSImage (url);
Then to print it, I used the command;
partial void printButton (Foundation.NSObject sender) {
NSPrintOperation p = NSPrintOperation.FromView(this.imgCell.ControlView);
p.RunOperation();
}
Really surprised how easy that turned out to be!
Email Proxy on #Azure #Webservice
Here’s a generic way to use a webservice to send email, and it’s been tested with Amazon SES. Proxying email like this saves exposing your own IP address to recipients, to avoid problems with your ISP, or main hosting provider.
Here’s the code;
using System.Net.Mail;
using System.Text;
using System.Threading;
using System.Web.Services;/// <summary>
/// Summary description for EmailProxy
/// </summary>
[WebService(Namespace = “http://emailProxy.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class EmailProxy : WebService {[WebMethod]
public void SendEmail(string smtpHost, string username, string password, int port, string to, string from, string subject, string body) {var client = new SmtpClient
{
Port = port,
Host = smtpHost,
EnableSsl = true,
Timeout = 10000,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(
username,
password)
};
var mm = new MailMessage(from, to, subject, body)
{
BodyEncoding = UTF8Encoding.UTF8,
IsBodyHtml = true,
DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
};
client.Send(mm);
Thread.Sleep(1000);
}}
#Android #AppMarketing tip: Listing your app in China
Google play is virtually non-existent in china due to censorship rules, and Google’s exit from that market. Therefore to get downloads from china, you need to list your app on Chinese app stores. Most of which have an English version that you can navigate through. Here is a list of the top app stores in China – ordered by importance.
Myapp (Tencent)
Baidu Mobile Assistant
MIUI app store (Xiaomi)
HiMarket
Huawei App Store
Wandoujia
Anzhi Market
Google Play
Vivo
Access Tripadvisor API in PHP
<?php
$url = “http://api.tripadvisor.com/api/partner/2.0/map/42.33141,-71.099396/attractions?key=xxxx”;
$json = HttpGet($url);
$djson = json_decode($json, true);
$htmlOut = “<ul>”;
foreach($djson[“data”] as $poi)
{
$htmlOut = $htmlOut . ‘<li><a href=”‘ . $poi[“web_url”] . ‘”>’ . $poi[“name”] . ‘</a> – ‘ . $poi[“address_obj”][“address_string”] . ‘</li>’;
}
$htmlOut = $htmlOut . ‘</ul>’;echo $htmlOut;
function HttpGet($url) {
$ch = curl_init($url );
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT,’Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13′);
curl_setopt($ch, CURLOPT_REFERER, ‘http://www.google.com/’);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
return $output;
}
?>
Code object is not signed at all #Xamarin #Mac #OSX
It turns out that submitting a Mac app, you need to make sure the naming of your app is consistent, so your app is entitled exactly the same on the app store, and on the desktop. If you get this wrong, then your app will be rejected, and you’ll have wasted 1 week’s review on a silly mistake. (like me! – thanks Apple!)
So, In Xamarin, I went to change the Assembly name under Projects > Build > Output – and the project would no longer compile, – with an error saying “Code object is not signed at all” – I finally figured out that you have to open the plist file, view source, and change the executable file and mono bundle executable.
I haven’t figured out how to use special chars in the name of the project, but hopefully apple will let me away with having no spaces in my executable file name – fingers crossed!
Updating to the latest version of Cordova PhoneGap
After receiving a message from Google some time ago saying that security vulnerabilities in older versions of Cordova PhoneGap meant that my apps could be de-listed, I decided to go and upgrade my Cordova Setup, just to keep ahead of the curve.
So, step 1 (this is on a Mac, but should be similar on a PC)
sudo npm update -g cordova
cordova platform check
cordova platform update android
cordova platform update ios
Now, I noticed that all my ajax requests were failing with a 404 error, so I learned that you had to add a new plugin
cordova plugin add cordova-plugin-whitelist
Added this into the config.xml (probably overkill)
<allow-navigation href=”*” />
<!– The above is equivalent to these three declarations –>
<allow-navigation href=”http://*/*” />
<allow-navigation href=”https://*/*” />
<allow-navigation href=”data:*” />
<access origin=”*”/>
<allow-navigation href=”*”/>
<allow-intent href=”*”/>
and I added this into the HTML:
<meta http-equiv=”Content-Security-Policy” content=”* * ‘self’ default-src ‘unsafe-inline’ ‘unsafe-eval’ http://* https://* data: cdvfile://* content://*;”>
When building the release APK for Android, I noticed that ant.properties no longer had any effect, so you now have to include a build.json file in the project root as follows
{
“android”: {
“release”: {
“keystore”: “android”,
“storePassword”: “xxxx”,
“alias”: “android”,
“password” : “xxxx”,
“keystoreType”: “”
}
}
}
The keystore file has to be in the project root – this doesn’t allow absolute paths.
Generate Random string in MS-SQL within UDF
Just modified some code posted on stackoverflow to generate a random string with SQL, to fit it into a UDF (User defined function) as follows;
CREATE VIEW rndView
AS
SELECT crypt_gen_random(8) rndResultcreate function randomString
( ) returns varchar(8) as
BEGIN
declare @BinaryData varbinary(max), @CharacterData varchar(max)SELECT @BinaryData = rndResult FROM rndView
set @CharacterData=cast(” as xml).value(‘xs:base64Binary(sql:variable(“@BinaryData”))’, ‘varchar(max)’)return @CharacterData
END
The secondary view is required to get around a limitation that UDF’s are not supposed to change database state. – It does mean that it is limited to generating fixed-length random strings though (i.e. 8 chars)
