Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS Objective C Completion Block不会在需要时从Azure Mobile Apps Framework方法返回数据。构建捆绑应用程序_Ios_Objective C_Azure_Asynchronous_Completion - Fatal编程技术网

iOS Objective C Completion Block不会在需要时从Azure Mobile Apps Framework方法返回数据。构建捆绑应用程序

iOS Objective C Completion Block不会在需要时从Azure Mobile Apps Framework方法返回数据。构建捆绑应用程序,ios,objective-c,azure,asynchronous,completion,Ios,Objective C,Azure,Asynchronous,Completion,我已经为此挣扎了几个小时,也许几天了。我需要将查询结果返回到字符串中,并让我的方法返回字符串。但是,查询必须使用MicrosoftAzure的移动应用程序同步框架内的方法执行。我无法将此方法更改为包含允许我将数据传递回局部变量字符串的更改。所以我一直使用querywithpredicate:method,它只允许返回void,并且所有数据都被发送到完成块。我已经找到了许多块示例并尝试了它们,但是没有一个能够与Azure框架中的预定义方法一起工作。我还看到了许多使用数据的块的示例,但nspredi

我已经为此挣扎了几个小时,也许几天了。我需要将查询结果返回到字符串中,并让我的方法返回字符串。但是,查询必须使用MicrosoftAzure的移动应用程序同步框架内的方法执行。我无法将此方法更改为包含允许我将数据传递回局部变量字符串的更改。所以我一直使用querywithpredicate:method,它只允许返回void,并且所有数据都被发送到完成块。我已经找到了许多块示例并尝试了它们,但是没有一个能够与Azure框架中的预定义方法一起工作。我还看到了许多使用数据的块的示例,但nspredicate查询的所有结果都记录在nspredicate日志中,这对于调试非常有用,但并没有真正的用处。事实上,我被困在岩石和坚硬的地方之间,因为我也不能控制azureQuery方法的调用方法

第三方调用->azureQuery:(myMethod)->azureQuery调用Azure框架中的itemTable readWithPredicate:方法

第三方调用方正在等待查询结果

如何通过允许块完成查询工作来返回结果?还要记住,我正在构建一个捆绑包,因此将来可能无法访问所有iOS应用程序的AppDelegate Singleton类。我需要azureQuery从NSPredicate查询返回所需数据的方法

我已经尝试过的事情:

1) \u block NSString*data=>此失败数据从未填充 2) 创建了我的方法和完成块都可以访问的全局变量=>此操作失败。 3) 创建了一个while循环来检查不同的变量是否不为空。循环从未结束=>此操作失败。 4) 尝试在azureQuery的方法声明中创建块返回结果。这并没有达到预期的效果。它让我在另一个街区用另一种方法

我需要在某个时间点转义块,以将结果存储在无块表示法的NSString中

-(NSString*)azureQuery:(NSString *)tableName {
// Query Param
NSString *str = [NSString stringWithFormat:@"2017-07-06T03:56:38.569+00:00"];

// convert to date
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'+00:00'"];
NSDate *dte = [dateFormat dateFromString:str];
[dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'+00:00'"];
str = [dateFormat stringFromDate:dte];
dte = [dateFormat dateFromString:str];
NSLog(@"Date to use after formating: %@", dte);

// Create a predicate that finds items where complete is false
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"createdAt > %@", dte];

QSTodoService* serviceAzure = [[QSTodoService alloc] init];
MSTable *itemTable = [serviceAzure.client tableWithName:tableName];

__block NSString *myData;//maybe this will work
//begin query method
[itemTable readWithPredicate:predicate completion:^(MSQueryResult * _Nullable result, NSError * _Nullable error) {
    //actions inside the completion block
    NSMutableArray *stringArray = [[NSMutableArray alloc] init];
        if(error) {
            NSLog(@"ERROR %@", error);
        } else {
            for(NSDictionary *item in result.items) {
                NSString *value = [item objectForKey:@"mbsq"];
                [stringArray addObject:value];
            }

        }
    //results of query in string
    NSString * result2 = [stringArray componentsJoinedByString:@"\r"];
    self.fName = result2;

    }];//end of completion block

while(_fName.length == 0) {
    //buy me some time for completion block to populate fName Global Variable
}
NSLog(@"Did it populate:%@",self.fName);
return myData;
}

谢谢你的帮助

更新:我尝试使用一个完成处理程序块,但没有效果

当我回到调用方法时,我遇到了相同的问题,在发送返回错误代码后完成块。results.SetAsText(*outText2,*默认语言环境);永远不要及时开火

#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0

errorResult = 0;
dispatch_async(dispatch_get_main_queue(), ^{

//FMScripterViewController* cmd = [[FMScripterViewController alloc] init];
//[cmd azureQuery:tableName];

    FMScripterViewController* cmd = [[FMScripterViewController alloc] init];
    [cmd azureQuery:tableName withResponseCallback:^(NSString *responseDictionary) {

        //NSLog(@"test in plugin responses %@", responseDictionary);

        fmx::TextUniquePtr outText2;
        //const char *c = [rtnString UTF8String];

        const std::string bar([responseDictionary UTF8String]);

        std::cout << "Firehouse:" << bar;

        outText2->Assign ( bar.c_str(), fmx::Text::kEncoding_UTF8 );

        std::cout << "outText2:" << &outText2;

        fmx::LocaleUniquePtr default_locale;

        results.SetAsText ( *outText2, *default_locale );

        //results.SetAsText( *result_text, dat1.GetLocale() );
    }];
});

您的
azureQuery
代码不应返回值。它应该从调用者那里接受一个完成处理程序块,一旦得到结果,它就可以调用该块。Paulw,我尝试向azureQuery添加一个完成处理程序,但它将我放入另一个块中。带完成:(void(^)(NSString*result))块;这是我添加的AzureQuery,但当我的调用者初始化我的AzureQuery时,他们只能使用一个块来查看结果,无法从块中转义字符串。Paulw请使用完成处理程序块查看我的新编辑。调用者必须处理操作是异步的这一事实。异步操作在iOS开发中非常常见。调用者可以使用信号量或调度组阻止,直到完成处理程序更新了某些变量,但不建议这样做。dispatch\u queue\u t queue=dispatch\u queue\u create(“com.myapp.bgtask”,NULL);dispatch_sync(queue,^{dispatch_group_t group1=dispatch_group_create();dispatch_group_enter(group1);//执行一些查询方法dispatch_group_leave(group1);//等待完成块执行,然后继续脚本分派_group _Wait(group1,分派_TIME _FOREVER);};
errorResult = 0;

return errorResult;
}