OpenFeint and Phonegap view problem - iphone

I am testing my app on a ipod Touch 4g iOS 4.2. Please note I tested the app on an iphone 2G with iOS 4.2 and this was not an issue.
The initial OpenFeint approval view launches, but the Phonegap view immediately lauches soon after so that the user has no time to enable/ignore Openfeint.
Even worse, the top of the phonegap view is clipped off and you can see the the Openfeint approval screen sitting there behind it.
I can use the app and openfeint works in offline mode registering high score and achievements.
My impression of Openfeint is that its view should go straigh to the top whenever it launches but for some reason it's not happening here.
I'm trying a few UIView methods and property changes but no luck so far.
Anyone come across this or understand how either of the view systems work.
I'll continue my debugging and report back but let me know if anyone out there has a good idea and/or insight.
Thanks
Nigel

I think worked this out. May be a few bugs. Require more thorough testing. Will report back.
Basically I disabled the default Openfeint Approval process and set up my own one using the OpenfeintDelegate.h
(BOOL)showCustomOpenFeintApprovalScreen
{
SCNetworkReachabilityRef reach = SCNetworkReachabilityCreateWithName(kCFAllocatorSystemDefault, "google.com");
SCNetworkConnectionFlags flags;
SCNetworkReachabilityGetFlags(reach, &flags);
if(kSCNetworkReachabilityFlagsReachable & flags) {
// The internet can be accessed using the current connection.
UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:#"OpenFeint Approval"
message:#"Do you want the awesome leaderboard, acheivement and challenge features offered by OpenFeint? (Remember this data will be stored on OpenFeint servers)"
delegate:self
cancelButtonTitle:#"No thanks"
otherButtonTitles:#"Yes", nil
];
[alert show];
[alert release];
}
return YES;
}

Related

UIAlertView Causes Crash in iOS SDK 6.0

I recently submitted an app to App Store that has not been accepted yet. Meanwhile, I downloaded Xcode 4.5 and tested my app in iPhone 6.0 Simulator.
However, when I intend to show an UIAlertView, the app crashes on [myAlertView show] line with EXC_BAD_ACCESS error. It works fine with iPhone 5.1 Simulator.
Here's my code:
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"Are you sure?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[myAlertView show];
Is that normal? What am I doing wrong with my code?
Also, do you think I should resend my app to Apple?(Just asking your advice)
Thanks in advance.
Edit: Apple has rejected the app because of iOS 6 crash.
Delete this method and use the other method:
[myAlertView show];
Try this Method:
[myAlertView performSelectorOnMainThread:#selector(show) withObject:nil waitUntilDone:YES];
See this related Question:
UIAlertView shown from background thread and with no delegate creates EXC_BAD_ACCESS
User input and UI calls must come from the main thread. Many of them will work "most" of the time on other threads, but sometimes will crash. They are more likely to crash differently (more or less often) on a device than the simulator, but it's possible Apple made changes that affect that difference in iOS6.
And to your second question, I would answer yes, I would upload an updated binary for review as soon as you fix the issue, especially if you can reproduce this on a device (I strongly encourage you to attempt to reproduce it on a device). Otherwise, you may A) get accepted with a bug your users hate, or B) get rejected and have a an even longer delay and possibly more scrutiny. If you send an updated binary before review finishes it does put you at the "back of the line" AFAIK, but better than the alternatives.

iOS 5: programmatically turn bluetooth on and off

I saw that programmatically turning bluetooth on and off was a "private api" thing in previos versions of iOS that would get an app rejected from the apple itunes store.
But in iOS 5, I am aware of previously private things that are no longer private, such as programmatically changing screen brightness. Doing this will no longer get your app rejected in itunes with iOS 5, so I am wondering if this other things were available publicly, like the bluetooth adapter.
CoreBluetooth is publicly available in iOS 5. Unfortunately it only works for new Bluetooth LE (Low Energy) devices.
See CoreBluetooth Documentation
This is not public. You will get rejected.
According to the iOS 5.0 Release Notes there is no mention of any Bluetooth functionality being publicly available.
I needed to enable bluetooth programmatically. What I did was use the GKPeerPickerController, this asks you to enable bluetooth if it's not already on. Then on a call for the GKPeerPickerControllerDelegate I dismiss the picker.
Not perfect, you will see the "Searching for devices" for a short time, but It works in lack of another way of doing this (as far as I know).
GKPeerPickerController * peerpicker = [[GKPeerPickerController alloc]init];
peerpicker.delegate = self;
peerpicker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[peerpicker show];
When the peerpicker is ready to search there's a delegate method to return a GKSession for the picker to use. This is where you dismiss it.
-(GKSession*)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type
{
[picker dismiss];
[picker autorelease];
return nil;
}
And your app won't get rejected.
No, bluetooth is still not available :(

applicationWillTerminate problem

I want to show the UIAlertView when user Click the Iphone Home button( means Close the application)
I have done these Code
- (void)applicationWillTerminate:(UIApplication *)application
{
NSString *errorString =#"Testing";
UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:#"Alert" message:errorString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}
But UIAlertView is not Showing. please help
Thanks in Advance
The user aims to close your app when he/she presses the home button. Apple suggest to let him/her to that. What I want to say: Don't do that. I think it is even not possible.
Look at Problem with applicationShouldTerminate on iPhone:
The alert view is never shown because
the 'show' method does not block, and
therefore, the end of
'applicationWillTerminate' is reached
immediately after you create the
alert view and try to show it. I
believe this is by design. You can't
really begin asynchronous operations
in 'applicationWillTerminate'.
applicationWillTerminate: may not be called in the newer version of iOS when pressing the Home button because the app could be only entering the background mode, not actually terminating.
Even if it is actually called (either the app is really terminated, or you're moving the code to applicationWillEnterForeground:), showing the alert is useless because the alert is associated with the active app, and your app has gone inactive by the time the alert is shown! So what happened really is, the alert is gone when the user press the home button, and when they resume your app, they see a mysterious alert popping up.
Don't ask if the user wants to quit your app. This isn't the norm in iOS. Instead, save all states in applicationDidEnterBackground:, and restore them in applicationWillEnterForeground: and application:didFinishLaunchingWithOptions:, making the user feel as if the app has never been terminated.
You might not want to use applicationWillTerminate but rather applicationWillResignActive. Check older posts like this one for more info.
You can't show a uialertview when application receive SIGKILL(Exit) Command.You can call any file or background functions in applicationWillTerminate - To do that you need to set a key in your plist.
UIApplicationExitsOnSuspend - Boolean - YES.

iphone app crashes due to Low Memory but works fine in simulator

Dear all, I have a navigation-based app with about 60 UIControllerViews, which is divided into 4 sections.
I have run with the following : 1. Build and analyse : bulid is successful with no complains. 2. Instruments allocation and leaks : no leaks.
However, the app crashed in iPhone or iPad but works fine in simulator. There is no crash reports but I do see LowMemory.log in the crashreporter folder.
I have upgraded my iphone and ipad to 4.2
Does anyone have ideas what could be wrong? I have been reading and troubleshooting for a week.
Is there a need to remove/release the UIControllerViews?
The app crashes simply by navigating between the views.
Thank you for any help.
My app has a root view called contentViewController and users can navigate to 4 quizzes from here.
This is the code I use to return to my root view.
- (void)goHome {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Warning"
message: #"Proceed?"
delegate: self
cancelButtonTitle:#"Yes"
otherButtonTitles:#"No",nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
if (buttonIndex == 0) {
NSArray * subviews = [self.view subviews];
[subviews makeObjectsPerformSelector:#selector(removeFromSuperview)];
self.view = nil;
if (self.contentViewController == nil)
{
ContentViewController *aViewController = [[ContentViewController alloc]
initWithNibName:#"ContentViewController" bundle:[NSBundle mainBundle]];
self.contentViewController = aViewController;
[aViewController release];
}
[self.navigationController pushViewController:self.contentViewController animated:YES];
}
else {
}
}
The simulator isn't going to give you any useful information about memory warnings—your app, running there, effectively has access to all the memory the system's willing to give it. The device is where you need to be testing for memory usage, and if you're getting warnings and crashes, then you need to do some Instruments work to figure out where you can free up some of that memory.
Look at your xcode console. If you are getting a number of low memory warnings, then you need to be allocating and de-allocating your views on the fly because they are taking up too much memory on the device (the simulator isn't quite so memory restricted).
But it could be about a million other things causing your crash. Make sure you're doing a debug build (breakpoints on) so the debugger will kick in and hopefully you can see where on the stack your crash is occurring.
You have some good suggestions already. However I'd suggest spending a lot of time reviewing XCode's debugging tools documentation. This so you have a basic understanding of what they are capable of and how to use them. Follow that up with some reading on iOS memory management, auto release pools and the like.
For your app you need to realize that there is no swap space on iOS devices. So you are forced to manage memory to an extent that you mat not have to on other platforms. Generally that means you don't want to keep to much view data in memory if it can be avoided.
In the case of the current iPad there may only be about 110MB of RAM available to the app. Specific numbers probably are iOS version dependent. In any event you need to get an idea as to how large the data structures (in memory) are for your various views. 60 different views could be considered a lot depending upon memory usage, if you don't manage it correctly you are likely to run out very quickly. This not like programming in Java or other garbage collected language.
Lastly; even though this sounds like a memory management issue it could always be something else. If you still have trouble you will need to post code. Right now it is really guess work on our part. Just remember you do not have VM and there is no garbage collection.
You are using up memory, always remember if you allocate memory you must release it, in some cases you can use autorelease so you dont forget to release it after the void dealloc method before end.

Problem with applicationShouldTerminate on iPhone

I'm having a problem with applicationShouldTerminate.
What ever I do it seams that has no effect. Any help would be
appreciated.
I'm well versed in programing but this just gives me headache. Im going
over some basic tutorials for xcode , as I'm new to mac in general, and am currently looking at a simple flashlight app.
It exists but I would like to add a alert box here with option not to
quit.
(void)applicationWillTerminate:(UIApplication *)application
{
[application setIdleTimerDisabled:NO];
}
this has no effect, alert is closed even before its created.
(void)applicationWillTerminate:(UIApplication *)application
{
[application setIdleTimerDisabled:NO];
UIAlertView *alertTest = [[UIAlertView alloc]
initWithTitle:#"This is a Test"
message:#"This is the message contained
with a UIAlertView"
delegate:self
cancelButtonTitle:#"Button #1"
otherButtonTitles:nil];
[alertTest addButtonWithTitle:#"Button #2"];
[alertTest show];
[alertTest autorelease];
NSLog(#"Termination");
}
I did some reading online and found that it should be possible to do
this with
(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender
But no mater where I put that declaration I get error: syntax error
before NSApplicationTerminateReply.
There is no syntax error except that xcode seems not to recognize
NSApplicationTerminateReply as valid input.
Any sample code would be greatly appreciated.
I know this is a non-answer, but hopefully I can be helpful:
Displaying a "Really quit?"-type alert like this, even if you can pull it off technically (and I'm not sure you can), is a bad idea and is likely to either cause rejection from the App Store or, at best, an inconsistent user experience because no other apps do this.
The convention with iPhone apps is to save state if necessary, then yield control (for termination) as quickly as possible when the user hits the home button or switches apps.
To ensure a consistent experience, Apple probably has an aggressive timer in place to restrict what you can do in applicationWillTerminate. And even if they don't have a technical measure in place, they probably have an App Store approval policy to ensure that applications quit immediately when they're asked to.
applicationShouldTerminate and NSApplication do not exist on the iPhone. You have to use UIApplication.
The alert view is never shown because the 'show' method does not block, and therefore, the end of 'applicationWillTerminate' is reached immediately after you create the alert view and try to show it. I believe this is by design. You can't really begin asynchronous operations in 'applicationWillTerminate'.
With regards to the applicationShouldTerminate error, in case anyone's curious, NSApplicationTerminateReply and NSApplication seem to be deprecated...even though the OP's method is exactly how it appears in the docs!
Defining your method as the below should build with no errors:
-(BOOL)applicationShouldTerminate :(UIApplication *)application
I think I found the answer to what I wanted to do but will need to check it when I get back home.
Some directions were found here
http://blog.minus-zero.org/
The iPhone 2.0 software was recently released, and with it came the
ability for users to download native apps (i.e., not web sites)
directly to their phones from within the iPhone UI or via iTunes.
Developers (anyone who pays Apple 59GBP for the privilege) can then
write their own apps and have them available for purchase in the App
Store.
One limitation of the Apple-sanctioned SDK is that only one
application is allowed to be running at a time. This presents a
problem for apps such as IM clients, music players and other programs
whose functionality relies on being able to run in the background.
Another example (courtesy of James) would be an app that takes
advantage of the iPhone 3G's GPS chip to create a log of all the
places you visit.
However, there is a neat trick that I discovered: your app will only
get terminated if you switch away from it, and hitting the iPhone's
power button while your app is in the foreground doesn't count as
switching away. The upshot of this is you can create apps which
continue to run while the iPhone is in your pocket - perfect for the
GPS example.
Achieving this is as simple as implementing two methods in your
UIApplication delegate - applicationWillResignActive: and
applicationDidBecomeActive:. Here's a simple example to demonstrate
the effect.
In your UIApplication delegate header file, add a new ivar: BOOL
activeApp. Then, in your implementation, add the following three
methods:
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(#"resigning active status...");
activeApp = NO;
[self performSelector:#selector(sayHello) withObject:nil afterDelay:1.0];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(#"becoming the active app...");
activeApp = YES;
}
- (void)sayHello {
NSLog(#"Hello!");
if (!activeApp)
[self performSelector:#selector(sayHello) withObject:nil afterDelay:1.0];
}