0

ユーザーがメールを送信する時間を設定できるメールアプリケーションを作成していますか?UILocalNotificationを使用して、ユーザーが選択した時間にバックグラウンドプロセスで電子メールを送信できますが、アプリケーションがオンになっている場合に限ります。しかし、ユーザーがアプリケーションを閉じたときにメールを送信したいと思います。例:ユーザーが10分後にメールを送信する時間を選択し、その前にアプリを閉じました。

私を助けてください

以下は私のコードです:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

    NSLog(@"didReceiveLocalNotification");

    NSLog(@"\nNotification dic = %@ %@",notification.userInfo,notification.alertBody);

    dictUser=notification.userInfo;
    [dictUser retain];

    NSLog(@"dictuser124:%@",dictUser);
    [dictUser retain];

    if ([str_info4 isEqualToString:@"0"]) 
    {
        [self sendEMAIL];
    }
    else if ([str_info4 isEqualToString:@"1"]) 
    {
        [self sendSMS];
    }

}

-(void)sendEMAIL
{
    [dictUser retain];

    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];


    //testMsg.fromEmail = @"Lexi mobile";//nimit51parekh@gmail.com

    testMsg.fromEmail = str_uname;
    NSLog(@"str_Uname=%@",testMsg.fromEmail);

    str_info = [str_info stringByReplacingOccurrencesOfString:@"," withString:@""];
    testMsg.toEmail = str_info;
    NSLog(@"autoemail=%@",testMsg.toEmail);


    testMsg.relayHost = @"smtp.gmail.com";


    testMsg.requiresAuth = YES;


    testMsg.login = str_uname;
    NSLog(@"autoelogin=%@",testMsg.login);

    testMsg.pass = str_password;
    NSLog(@"autopass=%@",testMsg.pass);

    testMsg.subject = @"Schedule Sms And Email";


    testMsg.wantsSecure = YES; 

    NSString *sendmsg=[[NSString alloc]initWithFormat:@"%@",str_info2];
    NSLog(@"automsg=%@",sendmsg);

    testMsg.delegate = self;


    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,

                             sendmsg,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

    testMsg.parts = [NSArray arrayWithObjects:plainPart,nil];


    [testMsg send];

   // [self DeleteRowAfterSending];
    [self performSelector:@selector(DeleteRowAfterSending) withObject:nil afterDelay:5.0];
}



-(void)messageSent:(SKPSMTPMessage *)message

{
    [message release];

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Your email is sent successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

    [alert show];

    [alert release];

    NSLog(@"delegate - message sent");

}

-(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error{

    [message release];

    // open an alert with just an OK button

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fail" message:@"Message sending failure" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

    [alert show];

    [alert release];


    NSLog(@"delegate - error(%d): %@", [error code], [error localizedDescription]);

}
4

3 に答える 3

1

私の知る限り、アプリを閉じると操作を行うことはできません。これをバックエンドのサーバー側で操作して、自動的に操作を実行できます。

于 2012-05-28T06:28:19.217 に答える
0

すでに閉じられている場合、アプリから送信するメールを「スケジュール」する方法はありません。最善のオプションは、これらすべてをバックエンドサーバーで処理することです。アプリは、誰が、何を、いつ、どこにメッセージを送信するかを保存します。送信する必要のあるメッセージのキューをポーリングするcronジョブを設定します。スケジュールされた時刻が一致する場合は、電子メールを送信します。

于 2012-05-28T05:58:40.100 に答える
0

私の知る限り、アプリケーションが閉じられているときに何かを実行することは不可能であり、使用可能なアプリケーションのインスタンスがないことを私は知っています。

むしろ、バックエンドでSERVERを使用して同じようにプッシュ通知を実装することをお勧めします。ユーザーが電子メールを送信する必要があるデータベースの時間を節約し、それに応じてその時点で電子メールを送信するためのCRONSを作成できます。

于 2012-05-28T06:10:03.033 に答える