我正在處理手機差距iOS應用程序。我需要將didRegisterForRemoteNotificationsWithDeviceToken
中收到的APN令牌傳遞給我的Java腳本函數。stringByEvaluatingJavaScriptFromString不調用javascript函數
didRegisterFoRmoteNotification
如下:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken NS_AVAILABLE_IOS(3_0)
{
NSString* token = [[[[deviceToken description]
stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""] ;
NSLog(@"Device_Token -----> %@\n",token);
[self.viewController.webView loadHTMLString:@"<script type=text/javascript src=js/test.js></script>" baseURL:nil];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:@"myFunc('skdjch')"];
}
和JavaScript函數爲:
function myFunc(str){
alert(str)
};
但是,myFunc
是沒有得到調用。 如果我從其他一些java腳本文件中調用myFunc
,那麼它可以正常工作並顯示他的警報。 任何人都可以解釋我在做什麼錯?
你好Sudhan,是的,我是新的PhoneGap,所以努力奮鬥:)。我認爲你給出的例子是從javascript調用本地iOS功能,但我需要從本機代碼調用JavaScript函數來停止設備令牌。 –
praneti我只是回答了將令牌傳遞給您的javascript函數(phonegap應用程序)的方法,其次是您要求在webview上顯示警報,並將其放置在viewcontroller上?爲此使用NSNotificationCenter,以便委託使觀察者可以在視圖控制器上監聽.... – Sudhan