2012-03-12 10 views
2

私はデバイス上で私のアプリを実行するとすぐに任意のscreen.Butアプリケーションを表示せずに閉じられるような機能は、バックグラウンドで動作するようなアプリケーションを作成しています。ユーザーがアプリケーションのアイコンをクリックすると、スクリーンは表示されず、バックグラウンドで動作します。 2分後に警告メッセージが表示されます。それはどうですか?デバイスにインストールするとき、アプリケーションをバックグラウンドに送信するにはどうすればよいですか?

私は以下の通り、このためのコードを使用している: -

-(void)applicationDidFinishLaunching:(UIApplication *)application{ 
[application cancelAllLocalNotifications]; 
[self applicationWillTerminate:application];}-(void)applicationWillTerminate:(UIApplication *)application{ 
/* 
Called when the application is about to terminate. 
Save data if appropriate. 
See also applicationDidEnterBackground:. 
*/ 

UILocalNotification* ln = [[UILocalNotification alloc] init]; 
ln.fireDate =[NSDate dateWithTimeIntervalSinceNow:30]; 
ln.alertBody = [NSString stringWithFormat:@"Now app is working in Background."];   
ln.soundName = UILocalNotificationDefaultSoundName; 
[[UIApplication sharedApplication] scheduleLocalNotification:ln]; 
ln.hasAction=NO; 
[ln release]; 
exit(0);} 

しかし、私はしたいので、これは動作しません。では、このコードのバグは何ですか?それはどうですか?

事前に感謝しますが...

答えて

1

は手動[self applicationWillTerminate:application];を呼び出すことによって、離れてあなたのアプリを置くことはできません。これは、アプリケーションを終了するときに呼び出されるデリゲートメソッドであり、アプリケーションを終了するメソッドではありません。

ローカル通知をdidFinishLaunchingWithOptions:にスケジュールし、後でexit(0);に電話をかけてみることができます。スプラの画面(または黒い画面)のいくつかの種類は、おそらく表示されます。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

    [application cancelAllLocalNotifications]; 
    UILocalNotification* ln = [[UILocalNotification alloc] init]; 
    ln.fireDate =[NSDate dateWithTimeIntervalSinceNow:30]; 
    ln.alertBody = [NSString stringWithFormat:@"Now app is working in Background."];   
    ln.soundName = UILocalNotificationDefaultSoundName; 
    [[UIApplication sharedApplication] scheduleLocalNotification:ln]; 
    ln.hasAction=NO; 
    [ln release]; 
    exit(0); //this line kills the app (and gets your app rejected) 
    return NO; //this line is just to make compiler happy 
} 

これは間違いなくApp Storeでは承認されませんのでご注意ください。

+1

私はそれを証明することができます、それは確かにリンゴによって拒否されます。私は、コールが終了したときに偽のコールアプリと同様のことをしたいと思っていました。彼らはすべての出口(0)の呼び出しをチェックし、もし彼らがすぐにアプリケーションを拒否するものを見つける。 –

関連する問題