1

私は、urアカウントの投稿メッセージのための機能を追加しているアプリケーションを作成しています。今、私はこのイベントをスケジューリングのために追加しています。そのユーザーの助けを借りて、メッセージを書いて後で、または特定の日時に投稿することができます。このために、私はユーザーによって指定された日付に生成されるローカル通知イベントを使用しました。しかし問題は、通知が生成されたときに私はFacebook上の投稿メッセージに使用される関数を呼び出していることです。fbでメッセージをポストするスケジューリングイベントの実装方法

-(IBAction)save{ 
    NSString *str1=[NSString stringWithFormat:@"%@",txt_date.text]; 
    NSString *str2=[NSString stringWithFormat:@" %@",txt_time.text]; 
    str1=[str1 stringByAppendingFormat:str2]; 
    selected_label.text= str1; 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    NSDate *today=[NSDate date]; 
    NSDateFormatter* formatter_current = [[[NSDateFormatter alloc] init] autorelease]; 
    formatter_current.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
    //Set the required date format 
    [formatter_current setDateFormat:@"yyyy-MM-dd hh:mm a"]; 

    NSLog(@"current date is =%@",str1); 
    today=[formatter_current dateFromString:str1]; 
    NSLog(@"current date:-%@",today); 
    UILocalNotification* ln = [[UILocalNotification alloc] init]; 
    ln.alertBody = @"Wake Up Sid"; 
    ln.applicationIconBadgeNumber = 1; 
    ln.fireDate = today; //[NSDate dateWithTimeIntervalSinceNow:15]; 
    ln.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
    NSLog(@"alarm will activate on%@",today); 
    NSDateFormatter* formatter_alarm = [[[NSDateFormatter alloc] init] autorelease]; 
    NSLocale *uslocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; 
    [formatter_alarm setLocale:uslocale]; 
    [uslocale release]; 
    formatter_alarm.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"]; 
    [formatter_alarm setDateFormat:@"hh:mm a"]; 
    NSString *str=[formatter_alarm stringFromDate:today]; 
    NSLog(@"%@",str); 
    ln.alertBody = [NSString stringWithFormat:@"Your first appointment at %@",str]; 
    ln.soundName = UILocalNotificationDefaultSoundName; 
    ln.repeatInterval=NSDayCalendarUnit; 
    [[UIApplication sharedApplication] scheduleLocalNotification:ln]; 
    [ln release]; 
} 

とappdelegateファイルに私が受け取った通知と通話後のメッセージ機能のために、この機能を使用します:については私はこのコードを使用している通知を生成

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 
// Override point for customization after application launch. 

    self.viewController=[[demo_social_updatesViewController alloc]initWithNibName:@"demo_social_updatesViewController" bundle:nil]; 
    nav_controller=[[UINavigationController alloc] initWithRootViewController:self.viewController]; 
    // Add the view controller's view to the window and display. 
    [self.window addSubview:nav_controller.view]; 
    [self.window makeKeyAndVisible]; 
    appDelegate_acess_token=[[NSUserDefaults standardUserDefaults] stringForKey:@"access_token"]; 
     application.applicationIconBadgeNumber = 0; 
    // Handle launching from a notification 
    UILocalNotification *localNotif = 
    [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; 
    if (localNotif) { 
     NSLog(@"Recieved Notification %@",localNotif); 
    } 
    return YES; 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application{ 
    if (application.applicationIconBadgeNumber == 1) { 
     BOOL tmp=[Global_Class_parsing post_comment_fb:appDelegate_acess_token uesr_comment:@"testing message111"]; 
     if(tmp){ 

      UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"Sucessfully posted to photos & wall!" 
                  message:@"Check out your Facebook to see!" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil] autorelease]; 
      [av show]; 

     } 
     else{ 
      UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"error"message:@"Check connection!" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil] autorelease]; 
      [av show]; 
     } 
    } 

    /* 
    Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    */ 
} 

- (void)applicationWillEnterForeground:(UIApplication *)application{ 
    /* 
    Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 
    */ 
    if (application.applicationIconBadgeNumber == 1) { 
     BOOL tmp=[Global_Class_parsing post_comment_fb:appDelegate_acess_token uesr_comment:@"testing message111"]; 
     if(tmp){ 

      UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"Sucessfully posted to photos & wall!" 
                  message:@"Check out your Facebook to see!" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil] autorelease]; 
      [av show]; 

     } 
     else{ 
      UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"error"message:@"Check connection!" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil] autorelease]; 
      [av show]; 
     } 
    } 
} 

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 
    UIApplicationState state = [application applicationState]; 
    if (state == UIApplicationStateInactive) { 
     NSLog(@"Recieved Notification %@",notification); 
    } else { 
     NSLog(@"Recieved Notification method call."); 
    } 
} 

今の問題は、通知が生成し、applicationbadge番号ときということです1になると、関数は呼び出されず、ポストメッセージ関数は呼び出されません。どうすればそのエラーを修正できますか?

+1

[なぜ撮影された地方の通知方法が機能しないのですか?](http://stackoverflow.com/questions/8410638/why-didrecivedlocalnotification-method-not-working)再度質問するのではなく、元の質問を修正する必要がある場合は、それを編集するだけです。 – Abizern

答えて

1

私はこの問題の解決方法を得ています。私は、ポスト方法でスケジューリングを実装する方法が2つあります。もう1つはWebサービスを使用することです。私は両方を使い、よく働いています。

関連する問題