【问题标题】:Routing HTTP Server iphone路由 HTTP 服务器 iphone
【发布时间】:2015-02-13 00:23:18
【问题描述】:

我正在使用它来安装 mobileconfig 文件。

https://github.com/mattstevens/RoutingHTTPServer
Installing a configuration profile on iPhone - programmatically

在应用程序委托中,我写了这个。它来自应用程序,我将安装 mobileconfig 文件,它将进入 safari。之后,它将进入设置和安装。然后,它将返回 safari,然后从那里返回应用程序。但是,如果我打开 safari,它总是会路由到我的应用程序并且不会停止。我只需要这样做一次。我该怎么办?

httpServer = [[RoutingHTTPServer alloc] init];
[httpServer setPort:8000];                               // TODO: make sure this port isn't already in use
_firstTime = TRUE;
[httpServer handleMethod:@"GET" withPath:@"/start" target:self selector:@selector(handleMobileconfigRootRequest:withResponse:)];
[httpServer handleMethod:@"GET" withPath:@"/load" target:self selector:@selector(handleMobileconfigLoadRequest:withResponse:)];

NSMutableString* path = [NSMutableString stringWithString:[[NSBundle mainBundle] bundlePath]];
[path appendString:@"/test.mobileconfig"];
_mobileconfigData = [NSData dataWithContentsOfFile:path];

[httpServer start:NULL];



- (void)handleMobileconfigRootRequest:(RouteRequest *)request withResponse:(RouteResponse *)response    {
    [response respondWithString:@"<HTML><HEAD><title>Profile Install</title>\
    </HEAD><script> \
    function load() { window.location.href='http://localhost:8000/load/'; } \
    var int=self.setInterval(function(){load()},400); \
    </script><BODY></BODY></HTML>"];
}

- (void)handleMobileconfigLoadRequest:(RouteRequest *)request withResponse:(RouteResponse *)response  {

    if( _firstTime )
    {
        _firstTime = FALSE;
        [response setHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];
       [response respondWithData:_mobileconfigData];
    }

    else
   {
       [response setStatusCode:302]; // or 301
       [response setHeader:@"Location" value:@"Chan://"];
   }

}

【问题讨论】:

    标签: ios iphone http safari routes


    【解决方案1】:

    他们是您的 test.mobileconfig 文件中的错误,我有同样的问题,我仍在寻找来源。

    如果我得到它,我会发布解决方案。 编辑: 正如我之前所说,就我而言,文件不好,并且标题内容类型也没有应用。

    所以,要解决这个问题:

    1- 强制标头使用:

    [httpServer setDefaultHeader:@"Content-Type" value:@"application/x-apple-aspen-config"];
    

    2- 使用一个好的 mobileconfig 文件,这里是一个结构化的例子: (来源:link

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Inc//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>PayloadVersion</key>
        <integer>1</integer>
    
        <key>PayloadUUID</key>
        <string>randomUUID</string>
    
        <key>PayloadType</key>
        <string>Configuration</string>
    
        <key>PayloadIdentifier</key>
        <string>com.example.carddav</string>
    
        <key>Label</key>
        <string>A Carddav Profile</string>
    
        <key>PayloadContent</key>
        <array>
        <dict>
    
            <key>CardDAVAccountDescription</key>
            <string>A Carddav Description</string>
    
            <key>CardDAVHostName</key>
            <string>carddav.example.com</string>
    
            <key>CardDAVPrincipalURL</key>
            <string>/principals/userid/</string>
    
            <key>CardDAVUsername</key>
            <string>userId</string>
    
            <key>CardDAVPassword</key>
            <string>password</string>
    
            <key>PayloadDescription</key>
            <string>Configures CardDAV account</string>
    
            <key>PayloadIdentifier</key>
            <string>com.example.carddav</string>
    
            <key>PayloadOrganization</key>
            <string>A nice company</string>
    
            <key>PayloadType</key>
            <string>com.apple.carddav.account</string>
    
            <key>PayloadUUID</key>
            <string>randomUUID</string>
    
           <key>PayloadVersion</key>
           <integer>1</integer>
        </dict>
        </array>
    </dict>
    </plist>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      相关资源
      最近更新 更多