Skip to main content

Posts

Showing posts from April 3, 2012

Is it even possible to change a UIButtons background color?

This one has me stumped. Is it possible at all to change the background color of a UIButton in Cocoa for iPhone. I've tried setting the background color but it only changes the corners. setBackgroundColor: seems to be the only method available for such things. [random setBackgroundColor:[UIColor blueColor]]; [random.titleLabel setBackgroundColor:[UIColor blueColor]];

Getting "Using two-stage rotation animation” warning with UIImagePickerController

I wrote simple code to test UIImagePickerController: @implementation ProfileEditViewController - (void)viewDidLoad { [super viewDidLoad]; photoTaker_ = [[UIImagePickerController alloc] init]; photoTaker_.delegate = self; photoTaker_.sourceType = UIImagePickerControllerSourceTypeCamera; photoTaker_.showsCameraControls = NO; } - (void)viewDidAppear: (BOOL)animated { [self presentModalViewController: photoTaker_ animated: NO]; } @end And I'm getting strange warnings like the following: 2010-05-20 17:53:13.838 TestProj[2814:307] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. 2010-05-20 17:53:13.849 TestProj[2814:307] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate Got any idea what this is about? Thanks a lot in advance!

NSDateFormatter"s init method is deprecated?

Per http://developer.apple.com/iphone/library/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html The init method of NSDateFormatter is "Available in iPhone OS 2.0 through iPhone OS 3.2", and therefore not in 4.0. Now, it certainly works, but this seems odd. Is this is a mistake or is there some other way to create a NSDateFormatter ?

Add iPhone push notification using ASP.NET server

Here's the overview. I need to add push notification to an iPhone app. Server side is ASP.NET in c#. What I would like is some coaching to work through the process. I will then post generic code for an iPhone project and an ASP.NET web app along with step-by-step instructions so that others can learn. Here is my understanding: Apply for APNS certificate and add it to keychain. (Not sure how to bring this to ASP.NET) Have iPhones register with registerForRemoteNotificationWithTypes, send the value to your server, and store in a DB. Seems like this code to register should be easy but I can't find a good sample. (No problem with sending the value to the ASP.NET server.) Your server app creates a payload string, does JSON encoding, sends to the APNS server for each (or can it be for groups) of iPhones using their device token that was saved into the DB. So to develop the addition, here are the pieces: The iPhone registration code

Can"t find iOS FaceTime protocol documentation

As per the title. I searched all through the Apple website, and cannot find anything about it. I am not an iPhone developer member (yet) so don't have access to that stuff. I just want to develop an Android application that can talk with the FaceTime protocol. It would be a bit silly if we all had to pay Apple just to view the FaceTime documentation to implement the protocol in our non-iOS applications.

Exit application in iOS 4.0

Before iOS4.0 clicking the home button on iPhone exits the application, and Apple had in their guide that programmatically exiting the application was not accepted. now everything changed in iOS4.0, clicking the home button puts your app in a suspended mode (multitasking).. and I think there should be a clear way for the user to exit the app, like an exit button. is it now OK with apple? and how can it be done?

NSDateFormatter returning nil in OS 4.0

I had the following code working on on OS 3.x NSString *stringDate = @"2010-06-21T20:06:36+00:00"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"]; NSDate *theDate = [dateFormatter dateFromString:stringDate]; NSLog(@"%@",[dateFormatter stringFromDate:theDate]); but now in the newest xcode 3.2.3 under the iOS4 simulator, the varialble theDate is nil. I have looked through the class reference and do not see anything deprecated or implemented differently for iOS4 with these specific methods. What did i leave out?

iPhone Compiler Fails: No architectures to compile for

Hey guys, I'm trying to implement this in my iPhone app: http://code.google.com/p/core-plot/downloads/detail?name=alpharelease_0.1.zip&can=2&q=&sort=-uploaded . I figured I'd first try to run the sample they provide. I'm attempting to open and compile the project located in /Source/examples/CPTestApp-iPhone/ . It says my base SDK was missing right off of the bat, so I edited the Project settings and the Active Target to use the iOS4 SDK, which I've done before for samples and had work. I'm not sure what to do. I'm running one of the newest Unibody Macbooks, with 10.6.4. Here is my full error: // - start - // Check dependencies [BEROR]No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=i386, VALID_ARCHS=armv6 armv7). // - end - // Thoughts? Thanks! Josh

Testing view helpers

I'm currently working on a Rails plugin used for generating iPhone specific HTML meta-tags. I'm trying to use ActionView::TestCase for unit tests but keep getting the same error. See file contents and error below. Any ideas or help would be much appreciated. test_helper.rb require 'rubygems' require 'test/unit' require 'active_support' require 'action_view' require File.join(File.dirname(__FILE__), '..', 'lib', 'iphone_helper') iphone_test_helper.rb require 'test_helper' class IphoneHelperTest < ActionView::TestCase test 'br' do tag = tag('br') assert_tag_in tag, '<br />' end end error RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers

Check for private API "usage&rdquo; yourself?

So, we all know Apple forbids using private or undocumented APIs in iOS apps. I have no problem with this, as there are sound technical reasons for why this is a good idea. However, twice now I've had an app rejected for using private APIs, when this was not actually the case. It's not difficult -- the private APIs include symbols like connectionState , setThumbnail , setOrder and so on. Any calls you make to methods named as such will be flagged as a private API use, even if the method being called is something you have defined yourself. For a program doing something with connections, thumbnails or the order of things, the above mentioned method names aren't all that unlikely. Getting rejected for this and having to rename a method and resubmit delays everything by at least a week while you wait for a new review. So is there a way, using nm , class dumps of the iOS frameworks, etc to find out for yourself if your method names conflicts with anything in there? If s

Get launch orientation of iPad app

In my iPad app, I need to run some layout code to set the proper layout depending on the orientation. By default, the layout is configured for the landscape orientation, so in the case that the app starts in portrait mode, I need to take extra action to configure the views properly for display in portrait. In my -application:didFinishLaunchingWithOptions: method, I check the orientation using [[UIDevice currentDevice] orientation] . The problem here is that it always returns portrait even if the app is starting in landscape. Is there any way around this?

Deleting an app in iTunes Connect

Apple has introduced the possibility of deleting an app. Quoting the iTunes Connect guide: If you have created an app in iTunes Connect that you no longer need to see or manage, you can delete it from your iTunes Connect view. Deleting your app will not allow you to re-use your SKU or App Name and you will not be able to restore your app once deleted. So far so good. Then it gets slightly confusing: If you are selling your app to another developer for their own distribution and need to remove it from your iTunes Connect account, we recommend that you use App Delete so the App Name will be freed up for their use. Does this mean that I won't be able to reuse the name in my account, but other accounts will? Has anybody tried this?

Looking for a graph layout framework for iOS

For an iOS application I'm making I need to show groups of elements grouped together according to their type, and different groups of types separated from each other in a nicely done layout. I thought of using an undirected graph, with the grouped nodes all pointing to each other in a sort of circular reference, and then each group as another "meta-graph" with their nodes point at each other in a circular reference as well, hoping that together with a good graph layout framework this could be displayed nicely. Unfortunately, the only framework I keep hearing of is graphviz , but that doesn't seem to have an available port for iOS. So my question is either: Other ideas for how to implement what I need? A good implementation of graph layout for the iOS? An available port of graphviz for the iOS? Update : Please note, I am not looking for graph plotting frameworks, which are the frameworks used to draw graphs and charts (such as pie charts etc)

Try-catch exception handling practice for iPhone/Objective-C

Apologies if this question has already been answered somewhere else, but I could not find any decisive answer when searching on it: I'm wondering when try-catch blocks are to be used in objective-c iPhone applications. Apple's "Introduction to the Objective-C Programming Language" state that exceptions are resource intensive and that one should "not use exceptions for general flow-control, or simply to signify errors." From reading a few related questions here I also gather that people are not often using this method in practice. So I guess the question is: what are the situations when it's appropriate to use try-catch blocks when developing for iPhone/Objective-C and when should they absolutely NOT be used? For example, I could use them to catch beyond bounds and other exceptions when working with objects in arrays. I have a method which performs are few tasks with objects that are passed on in a number of arrays. The method returns nil if an er

Objective C parse hex string to integer

I would like to know how to parse a hex string, representing a number, in objective c. I am willing to use both an objective, or a C based method, either is fine. example: #01FFFFAB should parse into the integer: 33554347 Any help would be appreciated!

Convert String to Int Objective-C?

Really basic iPhone Objective-C question. I'm trying to extract a string (which is really a int) from an array and then use it as an int in a function. I'm trying to convert it to a int using intValue. Here's the code I've been trying. NSArray *_returnedArguments = [serverOutput componentsSeparatedByString:@":"]; [_appDelegate loggedIn:usernameField.text:passwordField.text:(int)[[_returnedArguments objectAtIndex:2] intValue]]; I get the error passing argument 3 of 'loggedIn:::' makes pointer from integer without a cast Thanks for the help, Christian Stewart

Android: How to track down the origin of a InflateException?

While starting my application I get the following warning in Logcat: 04-09 10:28:17.830: WARN/WindowManager(52): Exception when adding starting window 04-09 10:28:17.830: WARN/WindowManager(52): android.view.InflateException: Binary XML file line #24: Error inflating class <unknown> 04-09 10:28:17.830: WARN/WindowManager(52): at android.view.LayoutInflater.createView(LayoutInflater.java:513) 04-09 10:28:17.830: WARN/WindowManager(52): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) 04-09 10:28:17.830: WARN/WindowManager(52): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 04-09 10:28:17.830: WARN/WindowManager(52): at android.view.LayoutInflater.inflate(LayoutInflater.java:385) 04-09 10:28:17.830: WARN/WindowManager(52): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 04-09 10:28:17.830: WARN/WindowManager(52): at android.view.LayoutInflater.inflate(LayoutInflater

How to obtain MAC address of WiFi network interface?

It seems the java.net.NetworkInterface implementation of android does not have a byte[] getHardwareAddress() method http://developer.android.com/reference/java/net/NetworkInterface.html I've found several forums of people trying to do this with no definitive answer, I need to get a somewhat cross-device UUID, so I can't rely on phone numbers or in ANDROID_ID (which can be overwritten and which I think depends on the user having a google account) http://developer.android.com/reference/android/provider/Settings.Secure.html#ANDROID_ID In linux you can use ifconfig or read from /proc/net/arp and you can easily get the Hardware address. Is there a file in android that I can read? There has to be a way to get this address since it's shown in the "Settings > About Phone > Status" of the phone.

ArrayIndexOutOfBoundsException with custom Android Adapter for multiple views in ListView

I am attempting to create a custom Adapter for my ListView since each item in the list can have a different view (a link, toggle, or radio group), but when I try to run the Activity that uses the ListView I receive an error and the app stops. The application is targeted for the Android 1.6 platform. The code: public class MenuListAdapter extends BaseAdapter { private static final String LOG_KEY = MenuListAdapter.class.getSimpleName(); protected List<MenuItem> list; protected Context ctx; protected LayoutInflater inflater; public MenuListAdapter(Context context, List<MenuItem> objects) { this.list = objects; this.ctx = context; this.inflater = (LayoutInflater)this.ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i(LOG_KEY, "Position: " + position + "; convertView = " + convertView + "; parent=" + parent); MenuItem item = list.get(p

Android Market, Search results position Mystery

How is an app's position in the Android Market search results determined? Is it as mysterious and complex as Google Web search results? We obviously don't want to change any words in our app's title or description that would hurt our position. Same question applies for not only search results, but when clicking on a Category in the Android Market. How is the order of the list determined? Hopefully someone here can help. I would think that Google would have published some guidelines at least that could help, but I haven't found anything yet.

Android Preferences: How to load the default values when the user hasn"t used the preferences-screen?

I am using a PreferenceActivity to let the user set some values. I am feeding it the xml file with the defined preferences. I have set all the android:defaultValue="" for them. When I start my application, I need the preferences, or if they are not set yet manually, I want the default values: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean value = prefs.getBoolean("key"), false); However, when android:defaultValue="true" I still get false . So, it looks like the defaultValues set in the XML are not used anywhere but when initializing the preferences-screen. I don't want to hardcode the default values in the getBoolean() method. So, is there a way get the default-values with only defining these in 1 place?

Focusable EditText inside ListView

I've spent about 6 hours on this so far, and been hitting nothing but roadblocks. The general premise is that there is some row in a ListView (whether it's generated by the adapter, or added as a header view) that contains an EditText widget and a Button. All I want to do is be able to use the jogball/arrows, to navigate the selector to individual items like normal, but when I get to a particular row -- even if I have to explicitly identify the row -- that has a focusable child, I want that child to take focus instead of indicating the position with the selector. I've tried many possibilities, and have so far had no luck. layout: <ListView android:id="@android:id/list" android:layout_height="fill_parent" android:layout_width="fill_parent" /> Header view: EditText view = new EditText(this); listView.addHeaderView(view, null, true); Assuming there are other items in the adapter, using the arrow keys will move the s

Animate change of view background color in Android

How do you animate the change of background color of a view in Android? For example: I have a view with a red background color. The background color of the view changes to blue. How can I do a smooth transition between colors? If this can't be done with views, an alternative will be welcome.

Is it possible to have multiple styles inside a TextView?

I was wondering if its possible to set multiple styles for different pieces of text inside a TextView. For instance, I am setting the text as follows: descbox.setText(line1 + "\n" + line2 + "\n" + word1 + "\t" + word2 + "\t" + word3); Now, is it possible to have a different style for each text element? I mean bold for line1, normal for word1 and so on... I found this http://developer.android.com/guide/appendix/faq/commontasks.html#selectingtext : // Get our EditText object. EditText vw = (EditText)findViewById(R.id.text); // Set the EditText's text. vw.setText("Italic, highlighted, bold."); // If this were just a TextView, we could do: // vw.setText("Italic, highlighted, bold.", TextView.BufferType.SPANNABLE); // to force it to use Spannable storage so styles can be attached. // Or we could specify that in the XML. // Get the EditText's internal text storage Spannable str = vw.getText(); // Create our span secti

Targeting Android with Scala 2.8 Trunk builds

The definitive reference for using Scala on android seems to be here: http://www.scala-lang.org/node/160 Unfortunately, all the references on using scala with android are based around Scala 2.7 and refer to a custom build android-library.jar, with a couple of cryptic references suggesting that this custom build isn't needed for later versions of android (I'm using 2.1 / API v7) So... What are the steps needed to use Scala 2.8 in an android project? Preferably using eclipse and the Android tools that Google supplies for that IDE.

Clickable widgets in android

The developer documentation has seemed to have failed me here. I can create a static widget without thinking, I can even create a widget like the analogue clock widget that will update itself, however, I can not for the life of me figure out how to create a widget that reacts to when a user clicks on it. Here is the best code sample that the developer documentation gives to what a widget activity should contain (the only other hint being the API demos, which only creates a static widget): public class ExampleAppWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i=0; i<N; i++) { int appWidgetId = appWidgetIds[i]; // Create an Intent to launch ExampleActivity Intent intent = new Intent(context, ExampleActivity.c

Android browser GREEN border on click

I want to develop a web application using HTML, CSS and Javascript one thing that is really annoying is that any link or button etc when clicked inside the Android browser gets highlighted with a green border. To demonstrate what I mean I have included a link to a page that contains a basic game written in CSS http://marbles2.com/app/ Is there any way that you are aware of to disable the click green border? Cheers Paul

Sending POST data in Android

I'm experienced with PHP, JavaScript and a lot of other scripting languages, but I don't have a lot of experience with Java or Android. I'm looking for a way to send POST data to a PHP script and display the result.

Getting rid of the gradient at the top of an Activity (Android)

How can I get rid of the gradient at the top of my screen (the very top of the blue in the screenshot below... below the notification bar)?

Test if file exists

I'm trying to open a file in android like this : try { FileInputStream fIn = context.openFileInput(FILE); DataInputStream in = new DataInputStream(fIn); BufferedReader br = new BufferedReader(new InputStreamReader(in)); if(in!=null) in.close(); } catch(Exception e) { } , but in case the file does not exists a file not found exception is thrown . I'd like to know how could I test if the file exists before attempting to open it.

Android without Java

After doing the whole "enterprise" programming for a while, I'm seriously disillusioned by the language itself and always feel quite hampered if I have to go back to it. The project size of your average Android app isn't too intimidating and the libraries are actually quite nice regarding their coding style, but if I could avoid Java, I'd certainly do. So that's the question: Can I avoid it? While there are lots of JVM language that would be an option on desktops and servers, the Dalvik VM and the devices themselves pose some limits. This seems to be a bit better in 2.2 with the JIT, but limiting myself to the cutting edge would be a rather harsh decision. The only alternative I know that's used somewhat seems to be Scala. Is there some possibility I'm missing? Clojure seems to run in exactly the problems I've illustrated above with Dalvik, but as the AppInventor is built on Kawa there might be hope for a Lisp on the mobile platform? What o

Android textview outline text

Is there a simple way to have text be able to have a black outline? I have textviews that will be different colors, but some of the colors don't show up on my background so well, so I was wondering if there's an easy way to get a black outline or something else that will do the job? I'd prefer not to have to create a custom view and make a canvas and such.

Android encryption

I am working on an android application, and I need to use encryption for one aspect of it. I am really indifferent to which algorithm I use (AES, DES, RSA, etc...). I am aware that Java has a crypto package, but I am not familiar with it at all. Can someone post an example on how to do an encrypt/decrypt function?

Android: Issue with acceptable file types via bluetooth

I've got a problem with pushing files to my Nexus One. It seems to me that there is only a small selection of file types that are accepted by my phone (such as jpg, gif and so on). I recently tried to push other files to my phone (in my case gpx) and my phone rejected it automatically. Is there a way to bypass or extend this filter in my program? Is there also a way to catch those files by a service?

set the absolute position of a view in Android

Is it possible to set the absolute position of a view in android? (I know that there is an AbsoluteLayout, but it's deprecated...) Lets say I have a screen 240x320px, and I want to put an ImageView which is 20x20px with its center at the position (100,100). What do I have to do? Thanks for the help, this is driving me crazy.