iOS应用程序从INRequestRideIntent扩展启动

时间:2018-02-10 03:18:29

标签: ios objective-c siri sirikit

我需要在应用程序中通过Siri实现乘车预订功能。我设法为应用程序添加扩展程序,现在我能够与Siri通信,但我没有成功启动应用程序以继续在应用程序中预订过程。 所以问题是,从INRequestRideIntent扩展启动app应该怎么做?

提前致谢!

RideIntentHandler.m

- (void)confirmRequestRide:(INRequestRideIntent *)intent completion:(void (^)(INRequestRideIntentResponse * _Nonnull))completion {
    INRideOption *rideOption = [[INRideOption alloc] initWithName:@"blah" estimatedPickupDate:[NSDate dateWithTimeIntervalSinceNow:300]];
    rideOption.userActivityForBookingInApplication = [[NSUserActivity alloc] initWithActivityType:@"blahblah"];

    INRideStatus *rideStatus = [[INRideStatus alloc] init];
    rideStatus.rideOption = rideOption;
    rideStatus.estimatedPickupDate = [NSDate dateWithTimeIntervalSinceNow:300];
    rideStatus.rideIdentifier = [NSUUID UUID].UUIDString;

    INRequestRideIntentResponse *response = [[INRequestRideIntentResponse alloc] initWithCode:INRequestRideIntentResponseCodeSuccess userActivity:nil];
    response.rideStatus = rideStatus;

    completion(response);
}        

AppDelegate.m

- (void)application:(UIApplication *)application handleIntent:(INIntent *)intent completionHandler:(void (^)(INIntentResponse * _Nonnull))completionHandler {  
     [Utils showCommonAlertWithMessage:@"blah"];  

     if ([intent isKindOfClass:[INRequestRideIntent class]]) {  
          [Utils showCommonAlertWithMessage:@"blah"];  
     }  
}  

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {  
     [Utils showCommonAlertWithMessage:@"blah"];  

     if ([userActivity.interaction.intent isKindOfClass:[INRequestRideIntent class]]) {  
          NSLog(@"%@", userActivity.userInfo);  
          [Utils showCommonAlertWithMessage:@"blah"];  
     }  

     return YES;  
}  

- (void)application:(UIApplication *)application didFailToContinueUserActivityWithType:(NSString *)userActivityType error:(NSError *)error {  
     [Utils showCommonAlertWithMessage:@"blah"];  
}

0 个答案:

没有答案