2013-05-02 5 views
0

나는 액세스 토큰을 얻기 위해 this link을 따르지만 일부는 특히 URL과 콘텐츠의 코드 아래에 새어 나옵니다.ios - 액세스 토큰을 얻는 방법?

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 

{ 

    if(_data) 
    { 
    NSString* content = [[NSString alloc] initWithData:_data 
               encoding:NSUTF8StringEncoding]; 

    [_data release]; 
    _data = nil; 

    NSString *jsString = @"<script type='text/javascript'>\ 
    window.external =\ 
    {\ 
    'Notify': function(s) { document.location = 'acs://settoken?token=' + s; },\ 
    'notify': function(s) { document.location = 'acs://settoken?token=' + s; }\ 
    }\ 
    </script>"; 

    //Here appending the above javascript with content 

    content = [jsString stringByAppendingString:content]; 

    NSURL *url = [[NSURL alloc] initWithString:@"https://converse.accesscontrol"]; 

    [webView loadHTMLString:content baseURL:url]; 
    } 
    } 

Gmail이나 야후에 로그인 할 때, 아래의 코드는 다음 URL을 확인 해고되지만, 여기 (조건이 실패 할 경우) 할 수없는 이해 할 수 .If, 내가 물어 노력하고있어. 위의 주어진 링크를 참조하십시오.

- (BOOL)webView:(UIWebView *)webView 
    shouldStartLoadWithRequest:(NSURLRequest *)request 
navigationType:(UIWebViewNavigationType)navigationType 

{ 

_url = [[NSURL alloc] initWithString:@"https://converse.accesscontrol.windows"]; 

    if(_url) 
    { 

    if([_url isEqual:[request URL]]) 
    { 
     return YES; 
    } 

    [_url release]; 
    } 

    _url = [[request URL] retain]; 
    NSString* scheme = [_url scheme]; 

    if([scheme isEqualToString:@"acs"]) 
    { 
    // parse the JSON URL parameter into a dictionary 
    NSDictionary* pairs = [self parsePairs:[_url absoluteString]]; 
    if(pairs) 
    { 
     WACloudAccessToken* accessToken; 
     accessToken = [[WACloudAccessToken alloc] initWithDictionary:pairs]; 
     [WACloudAccessControlClient setToken:accessToken]; 

     [self dismissModalViewControllerAnimated:YES]; 
    } 

    return NO; 
    } 

    [NSURLConnection connectionWithRequest:request delegate:self]; 

    return NO; 

    } 

아이디어가 있으십니까? 미리 감사드립니다.

답변

0

당신은

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    
    
  
   [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)]; 
  [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

} 

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
    
   self.strToken = [[[[deviceToken description] 
                      stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                     stringByReplacingOccurrencesOfString: @">" withString: @""] 
                    stringByReplacingOccurrencesOfString: @" " withString: @""]; 
    
   NSLog(@"%@",deviceToken); 
} 


- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { 
   NSString *str = [NSString stringWithFormat: @"Error: %@", error]; 
  
} 

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { 
    
   NSLog(@"user info  %@",userInfo); 
   UIApplicationState state = [application applicationState]; 
   if (state == UIApplicationStateActive) { 
       NSString *cancelTitle = @"OK"; 
       //NSString *showTitle = @"Show"; 
       NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"]; 
       UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil 
                                                           message:message 
                                                          delegate:self 
                                                 cancelButtonTitle:cancelTitle 
                                                 otherButtonTitles: nil]; 
       [alertView show]; 
       [alertView release]; 
        
        
   } 
    else { 
       //Do stuff that you would do if the application was not active 
   } 
} 
+0

우리가이 장치를 필요로 왜 답장을 보내 주셔서 감사합니다, 내가 올바른 길을 갈거야 ..... 장치 토큰을 성공적으로있어? –

+0

나중에 사파리에서 콘텐츠를로드하기위한 – hitesh

+0

코드를 얻었고 즐길 수 있습니다. 토큰을 얻는 것은 너무 복잡해서 UIWebview에서로드하려고합니다 –

관련 문제