正如 Nick 指出的那样,OneNote 应用程序需要额外的参数才能成功打开,而不会显示“无法打开链接”警报。这是我为解决问题所做的:
注意:在我的应用程序中,用户已经使用 LiveSDK(Microsoft 帐户登录)登录,因此我保存了他们的访问令牌。
我创建了一个“授权 OneNote”方法,该方法向 OneNote API 发送请求以在用户的默认笔记本中创建一个“页面”:
(void)AuthorizeOneNote
{
NSString *date = [NSString stringWithFormat:@"%@", [NSDate date]];
NSString *simpleHtml = [NSString stringWithFormat:
@"<html>"
"<head>"
"<title>\"%@\"</title>"
"<meta name=\"created\" content=\"%@\" />"
"</head>"
"<body>"
"<p></p>"
"</body>"
"</html>", @"Page Title", date];
NSData *presentation = [simpleHtml dataUsingEncoding:NSUTF8StringEncoding];
NSString *endpointToRequest = @"https://www.onenote.com/api/v1.0/pages";
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:endpointToRequest]];
request.HTTPMethod = @"POST";
request.HTTPBody = presentation;
[request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
[request setValue:[@"Bearer " stringByAppendingString:@"LIVE-ID-ACCESS-TOKEN"] forHTTPHeaderField:@"Authorization"];
objConnectionOneNote = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
这就是我处理响应的方式:
(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if (connection == objConnectionOneNote)
{
NSString *strData = [[NSString alloc]initWithData:objData encoding:NSUTF8StringEncoding];
NSMutableDictionary *dictData1 = [[NSMutableDictionary alloc] init];
dictData1 = [NSJSONSerialization JSONObjectWithData:objData options:kNilOptions error:nil];
oneNoteClientUrl = [dictData1 valueForKeyPath:@"links.oneNoteClientUrl.href"];
NSLog(@"Response: %@",oneNoteClientUrl);
NSLog(@"Response: %@",strData);
// Launch OneNote Client
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"onenote://"]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:oneNoteClientUrl]];
}
else
{
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"https://itunes.apple.com/us/app/microsoft-onenote-for-iphone/id410395246?mt=8&uo=4"]];
}
}
这里有几点需要注意:
希望能帮助到你!