To get some test images.
Get images from images.baidu.com, as follows,
create a shell script (.sh) file with following content
n=0
for file in *.jpg; do
file_name="$n.jpg"
n=$(( $n+1 ))
mv $file $file_name
done
Images are renamed to sequence number
Situee's BLOG. This a blog about iphone / mobile development, programming and other information technology. Welcome!
Tuesday, August 20, 2013
Monday, August 05, 2013
iOS handle Remote Push Notification
There are three cases to handle remote push notification.
- Your app was just launched
handle callback didFinishLaunchingWithOptions application launched by clicking "View" when app is not running - Your app was just brought from background to foreground
by clicking "View" when app is running in background.
handle callback didReceiveRemoteNotification - Your app was already running in the foreground
handle callback didReceiveRemoteNotification
Thursday, August 01, 2013
Using Ti.Google.Analytics in Titanium Mobile
In previous post "Titanium Javascript Execution Context", we know that different javascript execution context == different scopes. When implementing the Google Analytics, we will meet this problem.
The Ti.Google.Analytics project has been converted to use CommonJS. [1]
However, for windows created by window.url property, the global variable "analytics" is not available. For compatible reason, in window created by "url" property, we can still fire a global event to track. Like this,
The Ti.Google.Analytics project has been converted to use CommonJS. [1]
By using commonJS, all of our windows are in same context, we can simply call analytics.trackPageview directly inside windows.var gaModule = require('Ti.Google.Analytics'); var analytics = new gaModule('UA-XXXXXX-X'); // Call the next function if you want to reset the analytics to a new first time visit. // This is useful for development only and should not go into a production app. //analytics.reset(); // The analytics object functions must be called on app.js otherwise it will loose it's context Ti.App.addEventListener('analytics_trackPageview', function(e){analytics.trackPageview('/iPad' + e.pageUrl); }); Ti.App.addEventListener('analytics_trackEvent', function(e){ analytics.trackEvent(e.category, e.action, e.label, e.value); }); // Starts a new session as long as analytics.enabled = true // Function takes an integer which is the dispatch interval in seconds analytics.start(10,true); // You don't need to call stop on application close, but this is just to show you can callstop at any time (Basically sets enabled = false) Titanium.App.addEventListener('close', function(e){ analytics.stop(); });
However, for windows created by window.url property, the global variable "analytics" is not available. For compatible reason, in window created by "url" property, we can still fire a global event to track. Like this,
Ti.App.fireEvent("analytics_trackPageview", {pageUrl:'myhomepage'});
Titanium Javascript Execution Context
Some notes from "Understanding Execution Contexts"
http://developer.appcelerator.com/blog/2010/08/execution-contexts.html
"A JavaScript application running in a web browser is single threaded and has a global variable scope for the entire application. A Titanium Mobile application is similar"
app.js creates one execution context.
" New execution contexts are created when a window is created that points to an external JavaScript file, which would then bootstrap the new window."
We call it "heavyweight" window.
"When this new window is opened, it will have it’s own context and scope, so any variables declared in other contexts will not be available."
The variable defined in app.js is out of scope in win.js, because it's another execution context.
You can fire application-level events that will be received in all currently active execution contexts (app.js plus any open windows) via fireEvent. Custom events can have arbitrary data passed along with them, as shown in the example below:
"You can listen for these custom events in any context by using addEventListener at the application level as well. The example below listens for our custom event – you’ll notice that any properties of the object passed as the second argument to fireEvent are available on the event object the callback function takes as an argument:"
"Note that only ACTIVE execution contexts will receive a custom event when it is sent, so any windows that are not yet open will not receive the event."
http://developer.appcelerator.com/blog/2010/08/execution-contexts.html
"A JavaScript application running in a web browser is single threaded and has a global variable scope for the entire application. A Titanium Mobile application is similar"
app.js creates one execution context.
" New execution contexts are created when a window is created that points to an external JavaScript file, which would then bootstrap the new window."
We call it "heavyweight" window.
var win = Titanium.UI.createWindow({
title: 'New Window',
url: 'win.js'
});
"When this new window is opened, it will have it’s own context and scope, so any variables declared in other contexts will not be available."
The variable defined in app.js is out of scope in win.js, because it's another execution context.
You can fire application-level events that will be received in all currently active execution contexts (app.js plus any open windows) via fireEvent. Custom events can have arbitrary data passed along with them, as shown in the example below:
Ti.App.fireEvent('myCustomEvent', {
myCustomEventValue: 'someValue'
});
"You can listen for these custom events in any context by using addEventListener at the application level as well. The example below listens for our custom event – you’ll notice that any properties of the object passed as the second argument to fireEvent are available on the event object the callback function takes as an argument:"
Ti.App.addEventListener('myCustomEvent', function(event) {
Ti.API.info('You sent me: '+event.myCustomEventValue);
});
"Note that only ACTIVE execution contexts will receive a custom event when it is sent, so any windows that are not yet open will not receive the event."
Thursday, May 16, 2013
SVN create and switch to branch
Mac OS X 10.8.2
svn, version 1.6.18 (r1303927)
http://situee.blogspot.com/2013/05/svn-create-and-switch-to-branch.html
I want to work a new svn branch. And try the following comment
svn copy svn://server/path/trunk/project_name svn://server/path/branches/new_branch
But it's not ok. It returns error message:
"svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR are set, and no 'editor-cmd' run-time configuration option was found"
The command MUST have comment message like this
svn copy svn://server/path/trunk/project_name svn://server/path/branches/new_branch -m "create new branch"
The result is the project is copy to
svn://server/path/branches/new_branch/project_name
The we can go to the working copy and switch to the new branch by
svn switch svn://server/path/branches/new_branch/project_name
Everything is ok. You modification to the old working copy is still there.
The --relocate option of switch causes svn switch to do something different: it updates your working copy to point to the same repository directory, only at a different URL (typically because an administrator has moved the repository to another server, or to another URL on the same server).[1]
[1] http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.switch.html
The --relocate option of switch causes svn switch to do something different: it updates your working copy to point to the same repository directory, only at a different URL (typically because an administrator has moved the repository to another server, or to another URL on the same server).[1]
[1] http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.switch.html
Sunday, April 28, 2013
iOS Localize Image for Language of Applicaiton
How to localize images for iOS?
Put your images into localized folder, such as "en.lproj" , "zh.lproj"
This works for System Language.
But how about using language of application?
We can use string of app language by "NSLocalizedStringFromTable"
But there is NO such function for image.
Here is a solution.
Use the following code to get the path of the image of the app language.
NSString *path = [[NSBundle mainBundle] pathForResource:@"image_name" ofType:@"jpg" inDirectory:@"zh.lproj"];
or
NSString *path = [[NSBundle mainBundle] pathForResource:@"image_name" ofType:@"jpg" inDirectory:@"" forLocalization:@"zh"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
Thursday, April 25, 2013
Config Apache SVN server for Mountain Lion
After upgrade to Mac OS X 10.8 Mountain Lion.
My local SVN server is not working.
The setting should be the same, but the svn setting is removed from httpd.conf
How to get it work again? Let's GO!!
Create file "/etc/apache2/other/svn.conf",
Add the following lines into the "svn.conf"
#svn module
LoadModule dav_svn_module libexec/apache2/mod_dav_svn.so
LoadModule authz_svn_module libexec/apache2/mod_authz_svn.so
<Location /svn>
DAV svn
SVNPath "/svn"
AuthType Basic
AuthName "admin"
AuthUserFile /etc/your_user_name.htpasswd
Require valid-user
</Location>
sudzC SOAP web service namespace problem
I am using sudzC to generate objective-C codes to use SOAP webservice of a Java Tomcat server.
But is doesn't work. There must be some formatting problem.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://example.com/"><soap:Body>
<getMethod>
<arg0>aaa</arg0>
<arg1>8</arg1>
</getMethod>
</soap:Body></soap:Envelope>
return error message:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>
<soap:Fault><faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: unexpected element (uri:"http://example.com/", local:"arg0"). Expected elements are <{}arg0>,<{}arg1> </faultstring></soap:Fault>
</soap:Body></soap:Envelope>
server is expecting <{}arg0>, <{}arg1>
{} means the namespace is empty.
arg0 and arg1 should have NO namespace.
Friday, March 29, 2013
Apple iOS UDID Replacement - UUID,vendor,advertising id
Apple forbid all new / updated app of iphone to use UDID from May 1st, 2013.
There are some replacements : CFUUID/NSUUID, Vendor ID or Advertising ID.
There are some replacements : CFUUID/NSUUID, Vendor ID or Advertising ID.
Scope
|
Lifetime
end
|
Available
|
|
UUID
|
Application
|
Uninstall
app
|
iOS
2
|
Vendor
ID
|
Development
Team
|
Uninstall
all apps of the development team
|
iOS
6
|
Advertising
ID
|
Device
|
Wipe
device
|
iOS
6
|
Thursday, March 28, 2013
Titanium TableView row count
How to get the number of rows in tableview with Titanium?
TableView default has one section. "table.data" is the section array.
If you don't create section, your rows are in "section 0".
Get the row count by
table.data[0].rows.length;
or
table.data[0].rowCount;
Subscribe to:
Posts (Atom)

