2013-02-24 34 views
5

मैं एक उन ट्विटर अकाउंट तक पहुंच हासिल करने कोड लिख रहा हूँ, लेकिन इस मामले में जहां कोई भी खाता नहीं डिवाइस पर कर रहे हैं से निपटने परेशानी हो रही हूँ में काम नहीं करता। मुझे क्या करना चाहते हैं उपयोगकर्ता है कि आदेश ट्विटर के साथ प्रमाणित करने में, वे पहले उनकी सेटिंग में खाता बनाने की आवश्यकता होगी कह एक चेतावनी प्रदर्शित है।UIAlertView पूरा होने हैंडलर ब्लॉक

यहाँ मेरी कोड है:

self.accountStore = [[ACAccountStore alloc] init]; 
ACAccountType *accountTypeTwitter = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; 

[self.accountStore requestAccessToAccountsWithType:accountTypeTwitter options:nil completion:^(BOOL granted, NSError *error) { 
    if(granted) { 
     //Doesn't matter for the present case 
    } else if (error){ 

     [SVProgressHUD dismiss]; //not directly relevant to the present question, but it also doesn't work within the block, so I'm leaving it as a clue 

     switch ([error code]){ 
      case (6): 

       UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Twitter Account Detected" message:@"Please go into your device's settings menu to add your Twitter account." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
       [alert show]; //triggers an error 
       break; 

     } 
    } 
}]; 

मैं Xcode डिबगर के साथ कोई विशेषज्ञ हूँ, लेकिन जाहिरा तौर पर त्रुटि ACAccountStoreReply सूत्र में हो रहा है, के बारे में 25 कॉल गहरी के बाद [चेतावनी शो] कहा जाता है, एक में प्रक्रिया ucol_getVersion कहा जाता है। डीबगर राज्य EXC_BAD_ACCESS (कोड = 2, पता = 0xcc) बताता है।

मैंने स्टैक ओवरफ़्लो और इंटरनेट पर यूआईएलर्टव्यूज़ के संबंध में समाधान के लिए बड़ी संख्या में खोज की है, जो ब्लॉक में काम नहीं कर रहे हैं, और अलर्ट दिखाने वाली सामान्य समस्याओं के लिए भी (मैंने प्रतिनिधि के लिए अलग-अलग मूल्यों की कोशिश की है), और साथ ही साथ सामान्य समस्याओं के लिए भी अनुरोध करने के लिए कॉल AccessToAccountsWithType।

मैं भी ब्लॉक की मेरी समझ पर विभिन्न ऑनलाइन संसाधनों को पढ़ कर ऊपर ब्रश करने का प्रयास किया गया है, और ऑब्जेक्टिव-सी, 4 अलावा प्रोग्रामिंग के प्रासंगिक पृष्ठों।

किसी भी मदद की सराहना की जाती है।

उत्तर

21

तुम हमेशा यकीन है कि किसी भी UI इंटरैक्शन मुख्य थ्रेड पर किया जाता है बनाना चाहिए। एक dispatch_async में अपने UIAlertView कॉल लपेटें:

dispatch_async(dispatch_get_main_queue(), ^{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Twitter Account Detected" message:@"Please go into your device's settings menu to add your Twitter account." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
}); 

तुम भी कॉल के अंत में दो nil रों था।

+0

बिल्कुल सही .. ब्रावो ... +1 –

+0

लेकिन मैं इस alertview के प्रतिनिधि विधि कॉल करना चाहते हैं। ?? –

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^